Valik Posted June 21, 2004 Posted June 21, 2004 (edited) Prompted by this thread, here is a function which extracts the target from a shortcut file:Code removed because it didn't always works.You can text it with this:Code removed because it didn't always works.Error will be set to 1 if the file couldn't be opened. It will be set to 2 if the path couldn't be extracted correctly (May not be a valid lnk file, basically). In error cases, and empty stirng is returned, otherwise, the path should be returned. Edited June 22, 2004 by Valik
emmanuel Posted June 21, 2004 Posted June 21, 2004 ok, you've picked up the gauntlet, so I'll throw a complication in... I ran your script on a shortcut and got this: C:\aces_client\current\bin\aces_client_startup.bat yet, looking at the properties of the shortcut shows this: %ACES_CLIENT_HOME%\current\bin\aces_client_startup.bat -fns spseace1:5000;spseace2:5000 staring really hard at the shortcut in sciTE shows me all that text in there, each letter or symbol seperated by a NUL "I'm not even supposed to be here today!" -Dante (Hicks)
Valik Posted June 21, 2004 Author Posted June 21, 2004 It's also there in full path form, which is what I extract.
emmanuel Posted June 21, 2004 Posted June 21, 2004 It's also there in full path form, which is what I extract.I'm sorry, I don't catch your meaning. the sample script didn't show the additional info, is there something I need to do to gather that? "I'm not even supposed to be here today!" -Dante (Hicks)
Valik Posted June 22, 2004 Author Posted June 22, 2004 I found an issue where it won't read one of my shortcuts. I'm not sure exactly why this is the case yet. I'll look into it tonight or tomorrow and post any fix I find. As far as extracting other information, this was only meant to show that it's not that hard to extract the information and is only one method for extracting it. I checked and the shortcuts don't use a byte offset that I could see, so that means they use a certain byte pattern to denote the start of things. I'm sure if you google for the format of a lnk file, you can get lots of information explaining how to locate the start of each block of data. In fact, I've seen a file explaining how lnk's work, but I don't recall where. With that in hand, you can use the above as a base to extract any data from a lnk. Currently, I'm not too interested in doing this. I will see about getting it to work correctly, though.
CyberSlug Posted June 22, 2004 Posted June 22, 2004 Hmm... it's not working on my home computer. (Windows XP Pro sp1, NTFS partition, pretty normal system) I tested with a bunch of shortcuts plus a shortcut generated with AutoIt's FileCreateShortcut funciton. Here's what the code looks like in notepad: L À F TjÊQÄð_ sVÄ |"Ë+Á ³ PàOÐ ê:i¢Ø +00 /C:\ < 1 Ô0³ª WINDOWS & ï¾Í0£Õ0u¿ W I N D O W S H 2 + ` NOTEPAD.EXE . ï¾Í0H¤Ô0U N O T E P A D . E X E K 3 J ë[Ô WIN_XP C:\WINDOWS\NOTEPAD.EXE $ i ` X tecragump ¸S=¿ãGȬIôB'D§ÀØb 9`[¸S=¿ãGȬIôB'D§ÀØb 9`[ In SciTE, it begins L{NUL}{NUL}{NUL}{SOH}{DC4}{STX}... However, computer at work, also running XP Pro sp1, have shortcuts that produce much more readable text when opened in notepad Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Valik Posted June 22, 2004 Author Posted June 22, 2004 Following up a bit, here is a link to the format of various Windows file formats. There is a file written in C that reads the link information, however, at the top is an explanation of the file. I read it, but I need a hex editor to properly comprehend it (SciTE, while it shows the characters, doesn't present them in a nice column/row format like a hex editor, so finding byte offset's is hard). I recommend that file to anybody needing to extract data from a shortcut file.emmanuel, the arguments for a shortcut are stored in a different place than the actual path itself. I'll see about getting that to work tomorrow (Tuesday).
Valik Posted June 22, 2004 Author Posted June 22, 2004 That file was apparently wrong. I compiled it and it couldn't read shortcuts. I've now removed the function I posted since it didn't seem to work for all shortcuts. I don't really know how the file is organized and until I see a correct description, I can't reliably write something.
Chris_1013 Posted June 22, 2004 Posted June 22, 2004 Thanks for your efforts Valik. Suppose I need to do some research.
emmanuel Posted June 22, 2004 Posted June 22, 2004 That file was apparently wrong. I compiled it and it couldn't read shortcuts. I've now removed the function I posted since it didn't seem to work for all shortcuts. I don't really know how the file is organized and until I see a correct description, I can't reliably write something.I haven't read the whole thing, but... here's a msdn page on them...found that with a google search... "I'm not even supposed to be here today!" -Dante (Hicks)
Valik Posted June 22, 2004 Author Posted June 22, 2004 That just explains how to use the IShellLink COM interface to read/write shortcuts. It doesn't explain the format of a shortcut. I already knew about that interface. You can use VBScript and that interface to harvest information if you are familiar with VBScript. AutoIt even uses that interface to create shortcuts (FileCreateShortcut()).
SlimShady Posted June 22, 2004 Posted June 22, 2004 That just explains how to use the IShellLink COM interface to read/write shortcuts. It doesn't explain the format of a shortcut. I already knew about that interface. You can use VBScript and that interface to harvest information if you are familiar with VBScript. AutoIt even uses that interface to create shortcuts (FileCreateShortcut()).You'll figure it out sooner or later.Good luck.
CyberSlug Posted June 23, 2004 Posted June 23, 2004 Would this help? Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Valik Posted June 23, 2004 Author Posted June 23, 2004 Same thing. It uses the COM interface to get the information.
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