Jump to content

Get the path a shortcut points to


Valik
 Share

Recommended Posts

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 by Valik
Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 :D

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...