INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

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!

*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.

Jobs

Link files in Windows

Link files in Windows

(OP)
How do I determine the location of a text file pointed to by a .lnk file?
Thanks
Frank

RE: Link files in Windows

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

RE: Link files in Windows

I found this Vbscript example:
http://www.robvanderwoude.com/vbstech_shortcuts.php

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

# 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]]
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       :

RE: Link files in Windows

(OP)
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

RE: Link files in Windows

(OP)
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

RE: Link files in Windows

(OP)
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

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

(OP)
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

RE: Link files in Windows

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.
 

RE: Link files in Windows

(OP)
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

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!

Resources

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