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

Asked

Viewed 360 times

4

I am using Delphi XE7, 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, someone has some idea how to solve?

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. Use:

LinkArquivo := ArquivoPeloLink('C:\Users\Public\Desktop\Atalho.lnk')
  • 1

    Thank you for helping, I will give an analysis in your reply, if I succeed mark her.

  • 1

    You can also use the Windows environment variable %HOMEPATH% pointing to the directory defined for the current user. Just use the cited function in conjunction with GetEnvironmentVariable if you do not want to create a public shortcut.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.