Jump to content
Sign in to follow this  
leuce

Extract path from LNK file

Recommended Posts

G'day everyone

For what it's worth, I needed a way to extract the path of a file from an LNK file, and the following script does it. It works only on LNK files that you can see if you do a DIR command in the command prompt (some shortcuts don't seem to be LNK files). I haven't tested it extensively but it works on the files that I tested it on. The reason I wanted to do this was because I wanted to be able to copy or move a file from its current location to the locaiton of the shortcut.

$fo = FileOpen ("myfile.lnk", 16)
$fr = FileRead ($fo)
 
For $i = 1 to BinaryLen ($fr)
$character = BinaryMid ($fr, $i, 1)
If $character = ":" Then
$startpos = $i-1
ExitLoop
EndIf
Next
 
For $j = $startpos to BinaryLen ($fr)
$character = BinaryMid ($fr, $j, 1)
If $character = "0x00" Then
$endpos = $j-1
ExitLoop
EndIf
Next
 
MsgBox (0, "", BinaryToString (BinaryMid ($fr, $startpos, $endpos - $startpos + 1)), 0)

Samuel

Edited by leuce

Share this post


Link to post
Share on other sites

FileGetShortcut() does this for you in case you were wondering.

Thanks, I should have asked, shouldn't I? :D

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...