#1 2010-02-14 13:54

SafetyCar
Senior Member
Registered: 2008-04-28
Posts: 446
Website

Read Shortcut Target Path?

Is it possible to read the target path of a windows shortcut (*.lnk)?

I searched on google but I don't find nothing useful for pascal.  roll

Last edited by SafetyCar (2010-02-14 13:54)


If this software has helped you, consider getting your pro version. :)

Offline

#2 2010-02-14 20:46

Andrew
Senior Member
Registered: 2008-05-22
Posts: 542

Re: Read Shortcut Target Path?

I searched a bit and found this for you.

Just like the Exiv2 command-line tool can be used in a script as detailed here, you can similarly use Shortcut.exe to do the same.

The relevant command to be called from the script would be: Shortcut /f:"Shortcut to Movie.lnk" /a:q | find "TargetPathExpanded"

This will give you something like TargetPathExpanded=C:\Downloads\Movie File.avi, so you just need to extract what you want (path, file name etc.) from that string.

Hope this helps! smile

Offline

#3 2010-02-15 00:22

SafetyCar
Senior Member
Registered: 2008-04-28
Posts: 446
Website

Re: Read Shortcut Target Path?

OK, I made it work  big_smile

var
  Command, Output, TargetPath: string;

begin
  Command := 'Shortcut.exe /F:"'+Filepath+ '" /A:Q';
  ExecConsoleApp(Command, Output);
  TargetPath := ReplaceRegEx(Output, '^.+\r\nTargetPathExpanded=([^\r]+)\r\n.+$', '$1', False, True);
  FileName := WideExtractBaseName(TargetPath) + '.lnk';
end.

Thanks a lot  smile

Last edited by SafetyCar (2010-02-15 00:26)


If this software has helped you, consider getting your pro version. :)

Offline

#4 2010-03-23 19:16

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,379

Re: Read Shortcut Target Path?

Great work guys!

I might add this feature as a meta tag later on.

Offline

Board footer

Powered by FluxBB