Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2005 Mar : Resolving Shortcuts

www.cryer.info
Managed Newsgroup Archive

Resolving Shortcuts

Subject:Resolving Shortcuts
Posted by:"Andrew Jameson" (conta..@softspotsoftware.com)
Date:Sun, 20 Mar 2005 15:25:21

Hi,

I'm using the following code to get the executable associated with a given
lnk file :

procedure GetShellLinkInfo(LinkFile : WideString; var SLI :
TAJShellLinkInfo);
var
  ShellLink : IShellLink;
  AStr      : array[0..MAX_PATH] of char;
  FindData  : TWin32FindData;
begin
  OleCheck(CoCreateInstance(CLSID_ShellLink, nil, CLSCTX_INPROC_SERVER,
IShellLink, ShellLink));
  with (ShellLink as IPersistFile) do
    OleCheck(Load(PWideChar(LinkFile), STGM_READ));
  with SLI, ShellLink do begin
//    OleCheck(Resolve(0, SLR_ANY_MATCH or SLR_NO_UI));
    OleCheck(GetPath            (AStr, MAX_PATH, FindData, SLGP_SHORTPATH));
    PathName          := AStr;
    OleCheck(GetArguments       (AStr, MAX_PATH));
    Arguments         := AStr;
    OleCheck(GetDescription     (AStr, MAX_PATH));
    Description       := AStr;
    OleCheck(GetWorkingDirectory(AStr, MAX_PATH));
    WorkingDirectory  := AStr;
    OleCheck(GetIconLocation    (AStr, MAX_PATH, IconIndex));
    IconLocation      := AStr;
    OleCheck(GetShowCmd(ShowCmd));
    OleCheck(GetHotKey (HotKey ));
  end; {with}
end; {GetShellLinkInfo}

I've just noticed that the GetPath for some link files is returned as a
strange program referenced in the Windows Installer directory - in
particular some of the MicroSoft Office applications - for example Excel
returns :

'C:\WINDOWS\Installer\{90280409-6000-11D3-8CFE-0050048383C9}\xlicons.exe'

What am I doing wrong ? ... (The above code is frequently listed on Google
as the way to get the target executable)

Thanks

Andrew

Replies:

www.cryer.info
Managed Newsgroup Archive