Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Link files in Windows

Status
Not open for further replies.

fhutt

Programmer
Jul 7, 2006
79
AU
How do I determine the location of a text file pointed to by a .lnk file?
Thanks
Frank
 
I think you need to parse the binary. Consider:
Code:
% set a [open "c:/windows/context.lnk" r]
file872828
% 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
 
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
Code:
teacup install tcom

Now you are ready to go and something like this does the job:
shortcutinfo.tcl
Code:
[COLOR=#0000ff]# see the corresponding VBscript example:[/color]
[COLOR=#0000ff]# <a href="[URL unfurl="true"]http://www.robvanderwoude.com/vbstech_shortcuts.php">http://www.robvanderwoude.com/vbstech_shortcuts.php</a>[/URL][/color]

[COLOR=#804040][b]set[/b][/color] strTargetPath [COLOR=#ff00ff]"C:[/color][COLOR=#6a5acd]\\[/color][COLOR=#ff00ff]Users[/color][COLOR=#6a5acd]\\[/color][COLOR=#ff00ff]Roman[/color][COLOR=#6a5acd]\\[/color][COLOR=#ff00ff]Desktop[/color][COLOR=#6a5acd]\\[/color][COLOR=#ff00ff]Game.lnk"[/color]

[COLOR=#0000ff]# using Wscipt.Shell[/color]
[COLOR=#804040][b]package[/b][/color] require tcom
[COLOR=#804040][b]set[/b][/color] wshShell [::tcom::ref createobject WScript.Shell]
[COLOR=#804040][b]set[/b][/color] objShortcut [[COLOR=#008080]$wshShell[/color] CreateShortcut [COLOR=#008080]$strTargetPath[/color]]

[COLOR=#804040][b]puts[/b][/color] [[COLOR=#804040][b]format[/b][/color] [COLOR=#ff00ff]"Full Name         : %s"[/color] [[COLOR=#008080]$objShortcut[/color] FullName]]
[COLOR=#804040][b]puts[/b][/color] [[COLOR=#804040][b]format[/b][/color] [COLOR=#ff00ff]"Arguments         : %s"[/color] [[COLOR=#008080]$objShortcut[/color] Arguments]]
[COLOR=#804040][b]puts[/b][/color] [[COLOR=#804040][b]format[/b][/color] [COLOR=#ff00ff]"Working Directory : %s"[/color] [[COLOR=#008080]$objShortcut[/color] WorkingDirectory]]
[COLOR=#804040][b]puts[/b][/color] [[COLOR=#804040][b]format[/b][/color] [COLOR=#ff00ff]"Target Path       : %s"[/color] [[COLOR=#008080]$objShortcut[/color] TargetPath]]
[COLOR=#804040][b]puts[/b][/color] [[COLOR=#804040][b]format[/b][/color] [COLOR=#ff00ff]"Icon Location     : %s"[/color] [[COLOR=#008080]$objShortcut[/color] IconLocation]]
[COLOR=#804040][b]puts[/b][/color] [[COLOR=#804040][b]format[/b][/color] [COLOR=#ff00ff]"Hotkey            : %s"[/color] [[COLOR=#008080]$objShortcut[/color] Hotkey]]
[COLOR=#804040][b]puts[/b][/color] [[COLOR=#804040][b]format[/b][/color] [COLOR=#ff00ff]"Window Style      : %s"[/color] [[COLOR=#008080]$objShortcut[/color] WindowStyle]]
[COLOR=#804040][b]puts[/b][/color] [[COLOR=#804040][b]format[/b][/color] [COLOR=#ff00ff]"Description       : %s"[/color] [[COLOR=#008080]$objShortcut[/color] Description]]
Output:
Code:
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       :
 
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:
strTargetPath=....
to
strTargetPath=WScript.Arguments

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?
Thanks
Frank
 
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.
Frank
 
After a lot of searching and trial and error, I found the solutions.
1) The command line passing should be:
strTargetPath=WScript.Arguments(0)
instead of
strTargetPath=WScript.Arguments

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.
Frank
 
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?
 
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.
Thanks
Frank
 
fhutt,
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.
 
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.
Frank
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top