* * *

Author Topic: Extract path of a windows shortcut  (Read 263 times)

ufaforwork

  • Newbie
  • Posts: 1
Extract path of a windows shortcut
« on: August 18, 2017, 12:42:26 pm »
Hi everyone and thanks for trying to help me  8)
I work under Windows XP and i'd like to get the path of a .lnk file.
I don't find anyway to do this except doing it myself with opendialog...
After searching the net I found a solution for delphi with IShellLink, but it seems there's no way to get it work under lazarus.
If someone has a suggestion...


สมัครufabet

rvk

  • Hero Member
  • *****
  • Posts: 2682
Re: Extract path of a windows shortcut
« Reply #1 on: August 18, 2017, 01:08:20 pm »
Something like this:

Code: Pascal  [Select]
  1. uses ActiveX, ShlObj, Windows;
  2.  
  3. function GetLnkTarget(const LnkFilename: widestring): string;
  4. var
  5.   ShellLink: IShellLink;
  6.   PersistFile: IPersistFile;
  7.   Info: array[0..MAX_PATH] of char;
  8.   FindData: TWin32FindData;
  9. begin
  10.   Result := '';
  11.   CoCreateInstance(CLSID_ShellLink, nil, CLSCTX_INPROC_SERVER, IShellLink, ShellLink);
  12.   if ShellLink.QueryInterface(IPersistFile, PersistFile) = 0 then
  13.   begin
  14.     PersistFile.Load(PWideChar(LnkFilename), STGM_READ);
  15.     ShellLink.GetPath(@Info, MAX_PATH, FindData, SLGP_UNCPRIORITY);
  16.     Result := Info;
  17.   end;
  18. end;
  19.  
  20.  
  21. procedure TForm1.Button1Click(Sender: TObject);
  22. begin
  23.   Showmessage(GetLnkTarget('path_and_filename_to_your_lnk_file.lnk'));
  24. end;
(tested in Windows 10, not tested in Windows XP)

ASerge

  • Sr. Member
  • ****
  • Posts: 402
Re: Extract path of a windows shortcut
« Reply #2 on: August 18, 2017, 08:17:24 pm »
Code: Pascal  [Select]
  1. uses LazFileUtils;
  2.  
  3. procedure TForm1.Button1Click(Sender: TObject);
  4. begin
  5.   ShowMessage(GetShellLinkTarget('c:\Windows\System32\migwiz.lnk'));
  6. end;

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus