Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Link files in Windows

Link files in Windows

Link files in Windows

How do I determine the location of a text file pointed to by a .lnk file?

RE: Link files in Windows

I think you need to parse the binary.  Consider:


% set a [open "c:/windows/context.lnk" r]
% gets $a
L   ☺¶☻     ?      F?         Ç??D?☺-l??î?É☺  Ç??D?☺ ?     ☺               ? ¶ ▼PàO? ê:i►¢ +00?↓
 /C:\                   J 1     ?:Y?◄ PROGRA~1  2 ♥ ♦ ï?♂1ì?»:î?¶   P r o g r a m   F i l e s
↑ < 1     ?:ñ?► ConTEXT & ♥ ♦ ï?19ç?»:??¶   C o n T E X T   ▬ H 2  ? ►-v☺  ConTEXT.exe . ♥ ♦ ï?►
-v☺»:-?¶   C o n T E X T . e x e
So you can see that "c:\" is in there as is "Program Files" as is "ConTEXT" as is "ConTEXT.exe".  The path is, indeed, "c:\program files\context\context.exe".

Bob Rashkin

RE: Link files in Windows

I found this Vbscript example:

If you want to do the same, but with Tcl, then you need:
1. install ActiveTcl
2. install additionally package tcom with


teacup install tcom

Now you are ready to go and something like this does the job:


# see the corresponding VBscript example:
# <a href="http://www.robvanderwoude.com/vbstech_shortcuts.php">http://www.robvanderwoude.com/vbstech_shortcuts.php</a>

set strTargetPath "C:\\Users\\Roman\\Desktop\\Game.lnk"

# using Wscipt.Shell
package require tcom
set wshShell [::tcom::ref createobject WScript.Shell]
set objShortcut [$wshShell CreateShortcut $strTargetPath]

puts [format "Full Name         : %s" [$objShortcut FullName]]
puts [format "Arguments         : %s" [$objShortcut Arguments]]
puts [format "Working Directory : %s" [$objShortcut WorkingDirectory]]
puts [format "Target Path       : %s" [$objShortcut TargetPath]]
puts [format "Icon Location     : %s" [$objShortcut IconLocation]]
puts [format "Hotkey            : %s" [$objShortcut Hotkey]]
puts [format "Window Style      : %s" [$objShortcut WindowStyle]]
puts [format "Description       : %s" [$objShortcut Description]]


c:\Users\Roman\Work>tclsh shortcutinfo.tcl
Full Name         : C:\Users\Roman\Desktop\Game.lnk
Arguments         :
Working Directory : C:\Program Files\gnubg
Target Path       : C:\Program Files\gnubg\gnubg.exe
Icon Location     : ,0
Hotkey            :
Window Style      : 1
Description       :

RE: Link files in Windows

I looked at parsing the binary. Link files seem to vary quit a bit. My link files are different to yours Bong and they are different to my wife's computer. This may be difficult to implement to work correctly.
I also looked at tcom package. I have it. But looking inside the package's tcom.tcl I find it a little scary how it pokes around in the registry.
The .vbs option looked more promising. I copied the text from your link and changed the line:

I used the tcl script:
set out [exec wscript.exe shortcut.vbs reminders.txt.lnk]

But it comes up with a wscript.exe error to do with -
invalid property assignment 'strTargetPath'

I am obviously doing something wrong. Can you help with this?

RE: Link files in Windows

I actually have 2 problems.
1) The strTargetPath=WScript.Arguments doesn't work. I know because if I enter the actual path of the link file wscript no longer issues an error. So I don't know how to pass the command line argument to .vbs file.
2) When wscript works, it issues the response and is not passed to the tcl exec procedure. How do get wscript to pass it's output to exec and hence my variable in:
set out [exec wscript.exe shortcut.vbs reminders.txt.lnk]

I hope someone can help.

RE: Link files in Windows

After a lot of searching and trial and error, I found the solutions.
1) The command line passing should be:
instead of

2) The .vbs output passing to tcl instead of it's own window needs to have another line in the .vbs file changed to:
Wscript.StdOut.Write objShortcut.TargetPath
instead of
WScript.Echo "" & objShortcut.TargetPath

So the tcl script can be like this:
catch {exec wscript.exe shortcut.vbs $link} out

This way the variable $out contains the path of the file required and nothing if the link file is not found.
Thanks for your ideas.

RE: Link files in Windows

Hi fhutt,
I don't understand, why you don't want to use the tcom package, but instead you rather call Vbscript from your tcl script?

RE: Link files in Windows

Hello mikrom
I had a look at the tcom package. The tcl script fiddles with the registry. It also uses 2 .dll files and an .exe. I also wrap the tcl with freewrap to obtain an exe. I don't know how easy it would be to integrate tcom with freewrap. If I would need more of it's functionality, maybe I would have to use it.
In my case a small .vbs script and a one line tcl script does the job. Just seems more efficient.

RE: Link files in Windows

I was only curious what's wrong with tcom. IMO tcom is standard way how to work with windows COM objects from tcl. For example, I'm using the package to access database from tcl (like from Vbscript - using ADO).

My opinion is to write the whole script either in tcl or in VBscript. But you have surely your own reason why you want rather to call vbscript from tcl.

The info about freewrap was useful, I didn't hear about it before.

RE: Link files in Windows

Yes, I've used freewrap for years to wrap tcl scripts to obtain an exe file in windows. I found transferring exe programs to other computers much easier.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close