How to check if the application shortcut exists on the Desktop, if there is no create a

4

I'm using Delphi XE7, I wanted to know how to check if my application already contains a shortcut on the Desktop, if in case there is no create a shortcut.

From what I researched, I would have to look through the windows registry, does anyone have any idea how to solve it?

    
asked by anonymous 04.04.2017 / 22:28

1 answer

5

You can check if any of the icons have the target you are searching for. The following function may be useful.

uses
    Winapi.ShellAPI, 
    Winapi.ShlObj, 
    System.Win.ComObj, 
    System.Win.Registry, 
    Winapi.ActiveX

function ArquivoPeloLink(const NomeLink: String): String;
var
  AObject: IUnknown;
  ASLink: IShellLink;
  APFile: IPersistFile;
  WNomeLink: WideString;
  PFD: TWin32FindData;
begin
  AObject := CreateComObject(CLSID_ShellLink);
  ASLink := AObject as IShellLink;
  APFile := AObject as IPersistFile;

  WNomeLink := NomeLink;
  APFile.Load(PWideChar(WNomeLink), 0);
  SetLength(Result, MAX_PATH);
  ASLink.GetPath(PChar(Result), MAX_PATH, PFD, 0);
end;

I took it from here . Usage:

LinkArquivo := ArquivoPeloLink('C:\Users\Public\Desktop\Atalho.lnk')
    
04.04.2017 / 22:48