Mirror

Get filepath from shortcut (Views: 7)


Problem/Question/Abstract:

How to obtain the linked file from a shortcut

Answer:

uses ShellAPI;

function ExeFromLink(const linkname: string): string;
var
  FDir,
    FName,
    ExeName: PChar;
  z: integer;
begin
  ExeName := StrAlloc(MAX_PATH);
  FName := StrAlloc(MAX_PATH);
  FDir := StrAlloc(MAX_PATH);
  StrPCopy(FName, ExtractFileName(linkname));
  StrPCopy(FDir, ExtractFilePath(linkname));
  z := FindExecutable(FName, FDir, ExeName);
  if z > 32 then
    Result := StrPas(ExeName)
  else
    Result := '';
  StrDispose(FDir);
  StrDispose(FName);
  StrDispose(ExeName);
end;

<< Back to main page