Q: How to create a .LNK file using Tcl?

9 views
Skip to first unread message

D. Richard Hipp

unread,
May 18, 1999, 3:00:00 AM5/18/99
to
In Windows, I need to create a shortcut (a .LNK) file using
Tcl or Tcl/Tk. Can anybody give me a clue how this might
be done?
--
D. Richard Hipp -- d...@acm.org -- http://www.hwaci.com/drh/

Bill Schongar

unread,
May 18, 1999, 3:00:00 AM5/18/99
to
D. Richard Hipp wrote:
>In Windows, I need to create a shortcut (a .LNK) file using
>Tcl or Tcl/Tk. Can anybody give me a clue how this might
>be done?


From what I've seen, there's not a good, easy way to do it.
The functions you need are contained within Shell32.lib, but
there's no corresponding DLL you could link to and do a single
call. (Supposedly VB ships with a DLL like this, but I don't have
VB, so can't say for certain..)

The C code for it is rather messy, too.

Having said all that, I just ran a quick test to try and make and
easy way, and think I have one. It's cheating, really - I made an
executable using the WISE installer that accepts params on the
command line and then uses the built-in "Create Shortcut" command
to do the work. No C code for me today. : )

Right now it takes three params: The file you want to link to,
the full path for the link (.lnk) file you want to create, and
command line options. All separated by commas, like so:

makelnk.exe e:\foobar.txt,d:\mynewlink.lnk
makelnk.exe e:\mywish.exe,d:\somelnk.lnk,f:\apps\myscript.tcl
...

It's certainly not real robust, but it could easily be modified. I can
send it to you via email (or put it up for download off our site) if you
want.

-Bill

steve cassidy

unread,
May 19, 1999, 3:00:00 AM5/19/99
to
I've done something similar using the old dde extension talking to
the program manager (which still works on w95 and wNT for compatability
with
win3.1). I'm able to create start menu items, there may be a similar
interface
which allows creation of shortcuts anywhere on the system (eg the
desktop) --
I haven't looked. One reference which might be useful is:

http://msdn.microsoft.com/library/sdkdoc/shellcc/shell/DDE/DDE.htm

another is:

http://www2.imagine.com/eactive/ddedoc.html

Here's some code for the old dde extension which I'm sure could
be modified to work with the new dde code in 8.1.

-------------------------------------------------------------------------
# provide wrappers around dde to add things to the progman/Start menu
# modelled on the XlispStat installation file

# load the dde extensions
load dde

proc progman_exec {cmd args} {
puts "dde exec PROGMAN PROGMAN \[$cmd ([join $args ,])\]"
catch {dde exec PROGMAN PROGMAN "\[$cmd ([join $args ,])\]"}
}

proc progman_creategroup { groupname {grouppath ""}} {
progman_exec CreateGroup $groupname $grouppath
}
# showcmd can be:
#1 Activates and displays the group window. If the window is
minimized or
# maximized, Windows restores it to its original size and
position.
#2 Activates the group window and displays it as an icon.
#3 Activates the group window and displays it as a maximized
window.
#4 Displays the group window in its most recent size and position.
The
# window that is currently active remains active.
#5 Activates the group window and displays it in its current size
and
# position.
#6 Minimizes the group window.
#7 Displays the group window as an icon. The window that is
currently
# active remains active.
#8 Displays the group window in its current state. The window that
is
# currently active remains active.

proc progman_showgroup { groupname showcmd } {
progman_exec ShowGroup $groupname $showcmd
}

proc progman_minimizegroup {groupname} {
progman_showgroup $groupname 6
}

proc progman_deletegroup { groupname } {
progman_exec DeleteGroup $groupname
}

# additem
# cmdline: full command line of the item
# name: name to appear on the icon
# iconpath: path to an icon for the item
# default_dir: working directory for the program
proc progman_additem { cmdline name iconpath default_dir } {
progman_exec AddItem $cmdline $name $iconpath 0 0 0 $default_dir
}
-------------------------------------------------------------------------

it can be used like this:
-------------------------------------------------------------------------
proc emu_startupmenu {} {
global install
progman_creategroup "Emu Speech Tools"
emu_addscript emulabel "EmuLabel"
emu_addscript hquery "HQuery"
progman_additem "\"$install(whereemu)\\readme.txt\"" "README" "" ""
progman_additem "\"$install(whereemu)\\uninstall.bat\"" "Uninstall
Emu" "" "
"
progman_minimizegroup "Emu Speech Tools"
## add a registry entry for Emu, so that we can find where we are
installed
registry set "HKEY_LOCAL_MACHINE\\SOFTWARE\\SHLRC\\Emu" TEMPLATE_DIR
$instal
l(whereemu)
}
-------------------------------------------------------------------------
--
Steve Cassidy
--------------- Speech, Hearing and Language Research Center
Department of Linguistics
Tel: +61 2 9850 8729 Macquarie University
Fax: +61 2 9850 9199 NSW, 2109
Steve....@mq.edu.au Australia
http://www.shlrc.mq.edu.au/~steve -------------------------

Alexandre Ferrieux

unread,
May 19, 1999, 3:00:00 AM5/19/99
to
Bill Schongar wrote:
>
> D. Richard Hipp wrote:
> >In Windows, I need to create a shortcut (a .LNK) file using
> >Tcl or Tcl/Tk. Can anybody give me a clue how this might
> >be done?
>
> From what I've seen, there's not a good, easy way to do it.
> The functions you need are contained within Shell32.lib, but
> there's no corresponding DLL you could link to and do a single
> call.

Naive question: isn't there some DDE command to tell the Windoze
explorer 'Make Shortcut' ?

-Alex

Bill Schongar

unread,
May 19, 1999, 3:00:00 AM5/19/99
to


Yup, but only within the Start Menu, not as links anywhere on the drive.
The code Steve posted will make those shortcuts quite nicely. If that's
the only place you want a shortcut, DDE is a happy thing. : )

-Bill

Reply all
Reply to author
Forward
0 new messages