Sign in to follow this  
Followers 0
Chris_1013

Shortcut

16 posts in this topic

Can anyone suggest a way AutoIt (or some other tool) can read the location a shortcut (.lnk) file points to?

Share this post


Link to post
Share on other sites



This I had wondered for some time to. I just found the coordinates of the shortcut and used

; Double click at x,y

MouseClick("left", x, y, 1)

That way it moved to the location of the shortcut and double clicked it.


RK-DemonSpawned

Share this post


Link to post
Share on other sites

That's OK, but I don't actually want to click on the shortcut. I want a way to read .lnk files on a users PC, so I can read the path to a text file or somesuch to log this information.

Share this post


Link to post
Share on other sites

not sure if this is any help to you.. but LNK files can be read in notepad. They contain their directory information in plain text.

moo

Share this post


Link to post
Share on other sites

That's OK, but I don't actually want to click on the shortcut. I want a way to read .lnk files on a users PC, so I can read the path to a text file or somesuch to log this information.

Ahh my mistake. Not reading clearly this morning :D:huh2::)

RK-DemonSpawned

Share this post


Link to post
Share on other sites

not sure if this is any help to you.. but LNK files can be read in notepad. They contain their directory information in plain text.

moo

maybe you can open some .lnk files like that, but the few I tried it on, they either went straight to the exe it linked to, or showed garbage characters...

"I'm not even supposed to be here today!" -Dante (Hicks)

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I'm using winXP and I simply dragged them into an open notepad window and it showed the garbage as you say but within that is the plain text address. (ie C:\dcuments and settings\administrator\desktop\image.jpg )

if you wrote a script that looked for (<letter>:\) and went all the way until ..Jpg .exe .html .txt etc... or it searched for more than a single {space} as there is always an open block before it and after it. then you could extract it that way.

I tried using the filegetattrib but it gives nothing for .lnk files.. :D

anyway.. it's possible to extract it as text.. just takes some effort. Or perhaps requesting that this be added to the above mentioned command. When reading a .lnk store the directory information of the root file.

moo

Edited by cowsmanaut

Share this post


Link to post
Share on other sites

hmmm... it seems like the kind of thing autoit should be able to do... and now that I think about it, the kind of thing I want to be able to do. (I've got an app that has it's server defined in the shortcut, upgrading servers means finding and changing all icons on 20+ user's desktops)

so, can autoit fileread a .lnk file? time to find out, I guess.


"I'm not even supposed to be here today!" -Dante (Hicks)

Share this post


Link to post
Share on other sites

; read .lnk file to get path

$file = "C:\xcopy.lnk"
$s = FileGetSize($file)
$shortcut = FileOpen($file,0)
$text = FileRead($shortcut,$s)
if @error then 
   $err = "bad"
Else
   $err = "good"
EndIf

MsgBox(0,"reading lnk file",$text & @lf & "@error returns are "&$err)

I think I got the above right, and in my simple shortcut, it only returns a L for what's there. fyi, when I drop a .lnk file in scite on XP it doesn't show any ledgable text, though does show alot of characters.


"I'm not even supposed to be here today!" -Dante (Hicks)

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

L        À      F       æ*¶5OÄ°ÁÄJÍWIJ§5OÄ                     P N 2   Ê0Ï®  COW_IC~1.GIF  2 ï¾Ê0 ¯Ê0<¯   c o w _ i c o n 3 . g i f      r            3       q         ̯l   system C:\Documents and Settings\Administrator\Desktop\cow_icon3.gif  . \ c o w _ i c o n 3 . g i f / C : \ D o c u m e n t s   a n d   S e t t i n g s \ A d m i n i s t r a t o r \ D e s k t o p `      X       typhoon         zû·TçmÆG¸kàäã;äR`ºØºv Ð ä»±zû·TçmÆG¸kàäã;äR`ºØºv Ð ä»±   

you can see the output of the shortcut right there from notepad. I've tried it with LNK files from images, text files, EXEs, and even webpages. The only difference in in IE Shortcuts it's all plain text commands and addresses. I guess that's due to the fact that they point to webpages.

system C:\Documents and Settings\Administrator\Desktop\cow_icon3.gif

you can see this line in there.. if it's in the system drive you often get "system" witten before it.. You will notice you also get it's dos name in there "COW_IC~1.GIF " the typical 8.3 format.

it's even got the computer name in there. "typhoon"

lot's of info you can extract. :D

moo

Edit: that part about "system" and it being in the system drive is true but it's not what it's about. That is the name of the logical drive it's stored on. So if you had named your D:\ drive as "work" your section of the LNK would be "work d:\my folder\filename.exe"

Edited by cowsmanaut

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

looks like autoit's getting stopped by the NUL's at the begining of the file... I dropped another one into scite again and now see the path and file name there... maybe there's some way to get autoit past the NULLs in the file?

edit: I knew that this had already been covered. go check out Larry's workaround.

Edited by emmanuel

"I'm not even supposed to be here today!" -Dante (Hicks)

Share this post


Link to post
Share on other sites

looks like autoit's getting stopped by the NUL's at the begining of the file...  I dropped another one into scite again and now see the path and file name there...  maybe there's some way to get autoit past the NULLs in the file?

Just do a FileRead byte by byte and throw away any Chr(0)'s you get since they'll terminate the string. Dump all the other chars into a string, and then begin parsing.

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

the formula seems to be that when you reach "(letter):" then you go until you hit a "." and then 3 more letters and you stop.

as in the example above it's C: to .gif

In the case of .html links you'd need to do something else I think.

to explain it in english is easy enough.. however I think it's going to take a bit more than that to explain it in Computer. :huh2:

hmmmmm :D

Edited by cowsmanaut

Share this post


Link to post
Share on other sites

and, it'd also depend on what you'd be looking for, I'd be looking for any string that went server:port where I'd know what server and port are, but if they're old, I'd want to take the name of the lnk file and create a new shortcut overwriting it... I'm so not bothering right now.


"I'm not even supposed to be here today!" -Dante (Hicks)

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

It should be VERY easy to extract the data from a shortcut. Each path is preceed by the following sequence:

[DEL][NUL][NUL][NUL]DRIVENAME[NUL]PATH

DEL = ASCII character 16.

NUL = NULL character.

Read in a byte at a time, when you find DEL, check the next 3 characters and if they are emtpy strings, then if the next word is the drive name, you should be set. Then just keep reading to the next NULL.

Edit: Fixed a mistake where I accidentally said computer name instead of drive name.

Edited by Valik

Share this post


Link to post
Share on other sites

See here for a function I just wrote which extracts the target from any shortcut.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0