Chris_1013 Posted June 21, 2004 Share Posted June 21, 2004 Can anyone suggest a way AutoIt (or some other tool) can read the location a shortcut (.lnk) file points to? Link to comment Share on other sites More sharing options...
Falc0 Posted June 21, 2004 Share Posted June 21, 2004 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 Link to comment Share on other sites More sharing options...
Chris_1013 Posted June 21, 2004 Author Share Posted June 21, 2004 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. Link to comment Share on other sites More sharing options...
cowsmanaut Posted June 21, 2004 Share Posted June 21, 2004 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 Link to comment Share on other sites More sharing options...
Falc0 Posted June 21, 2004 Share Posted June 21, 2004 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 RK-DemonSpawned Link to comment Share on other sites More sharing options...
emmanuel Posted June 21, 2004 Share Posted June 21, 2004 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.moomaybe 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) Link to comment Share on other sites More sharing options...
cowsmanaut Posted June 21, 2004 Share Posted June 21, 2004 (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.. 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 June 21, 2004 by cowsmanaut Link to comment Share on other sites More sharing options...
emmanuel Posted June 21, 2004 Share Posted June 21, 2004 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) Link to comment Share on other sites More sharing options...
emmanuel Posted June 21, 2004 Share Posted June 21, 2004 ; 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) Link to comment Share on other sites More sharing options...
cowsmanaut Posted June 21, 2004 Share Posted June 21, 2004 (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. mooEdit: 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 June 21, 2004 by cowsmanaut Link to comment Share on other sites More sharing options...
emmanuel Posted June 21, 2004 Share Posted June 21, 2004 (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 June 21, 2004 by emmanuel "I'm not even supposed to be here today!" -Dante (Hicks) Link to comment Share on other sites More sharing options...
pekster Posted June 21, 2004 Share Posted June 21, 2004 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. Link to comment Share on other sites More sharing options...
cowsmanaut Posted June 21, 2004 Share Posted June 21, 2004 (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. hmmmmm Edited June 21, 2004 by cowsmanaut Link to comment Share on other sites More sharing options...
emmanuel Posted June 21, 2004 Share Posted June 21, 2004 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) Link to comment Share on other sites More sharing options...
Valik Posted June 21, 2004 Share Posted June 21, 2004 (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]PATHDEL = 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 June 21, 2004 by Valik Link to comment Share on other sites More sharing options...
Valik Posted June 21, 2004 Share Posted June 21, 2004 See here for a function I just wrote which extracts the target from any shortcut. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now