A ZIP file containing a PDF with detailed information on the link file format [7]

Anybody knows of an extension that lets you create unicode-aware shell links ? For example, for chinese version of windows (none of the above seems to work for me). APN I presume this comment was before the TWAPI item was added in the above list. twapi::write_shortcut should have not problems with Unicode strings.

RS tried reading such links, or "shortcuts", in a simpler, and pure-Tcl way. If you look at .lnk files in hexdump, you notice that they contain the string of what they link to, among other things. So I tried just to split on NUL bytes and see whether a snippet is a valid absolute path:

This is highly experimental, but it worked on the few examples I tried - please correct me if you know better! Simple links to directories and files work. Links that contain an executable invocation with arguments and icon, are a funny mix of ASCII and Unicode, so splitting on 0 is not a good idea there, and the above code does not work.

davidw - as far as I can tell the above will only work on English windows installations.

Peter Newman 24 November 2005: The easiest way to read/write *.LNK/*.URL files has to be to use Windows Script Host. As I understand it, this comes bundled with Windows 98 to XP. For other versions of Windows (or to upgrade to the latest version of WSH), you can download the latest version (5.6) (from Microsoft, for free).

Basically, WSH is two EXE files:- wscript.exe, which you call from GUI programs, and:- cscript.exe, which you run from the command line. Both run either VBScript or JScript script files. And both VBScript and JScript support a CreateShortcut method/function, which either creates a new, or opens an existing, *.LNK/*.URL file. You can then read or write the following properties:-

I run that script from VB .NET. But, from Tcl you'd go something like (I haven't tested it):-

set env("GetShortcutTarget_LinkFileFilespec") yourLinkFile
set env("GetShortcutTarget_DataFileFilespec") yourDataFile # (will be created/overwritten)
exec wscript.exe GetShortcutTarget.VBS # if you're using 'wish'
# --OR--
exec cscript.exe GetShortcutTarget.VBS # if you're using 'tclsh'
# ...some Tcl to read the first line of the output DataFile (which gives you the required TargetPath)...

You can easily modify the above to get the other properties too. Note that you don't have to worry about the paths to wscript.exe and cscript.exe. Windows figures this out itself.

Obviously, you can do the above from any language (not just Tcl). You can also; call COM objects, manipulate network drives and printers, do Office/Word/Excel automation, and quite a lot of other useful things from WSH/VBscript/JScript. And it's quite lightweight and fast too. I doubt you'd chuck Tcl for VBScript or JScript. But, for some Windows specific things (like those listed above), it's usually the easiest and most powerful solution. (And at least you're still scripting.)