This article shows how to add a link on the desktop to your application.
Adding a link (lnk) to the desktop directory is pretty simple. First we
will need to create a com object to be able to create our .lnk file.
Then we will have to get our desktop directory, which we will get using
the WIN32 API call SHGetSpecialFolderLocation() since the desktop
directory is a Windows special directory. I have gone over getting
special folder locations in a previous tip so this should be familiar to
you. We will be using Delphi's CreateComObject() function along with the
WIN32 API calls SHGetSpecialFolderLocation() and SHGetPathFromIDList()
with the PItemIDList record structure.
[CODE]
procedure TForm1.Button1Click(Sender: TObject);
var
tmpObject : IUnknown;
tmpSLink : IShellLink;
tmpPFile : IPersistFile;
PIDL : PItemIDList;
StartupDirectory : array[0..MAX_PATH] of Char;
StartupFilename : String;
LinkFilename : WideString;
begin
StartupFilename := 'c:\windows\notepad.exe';
tmpObject := CreateComObject(CLSID_ShellLink);
tmpSLink := tmpObject as IShellLink;
tmpPFile := tmpObject as IPersistFile;
{ tmpSLink.SetArguments('ADD COMMAND LINE PARAMETERS HERE');}
tmpSLink.SetPath(pChar(StartupFilename));
tmpSLink.SetWorkingDirectory(pChar(ExtractFilePath(StartupFilename)));
SHGetSpecialFolderLocation(0,
CSIDL_DESKTOPDIRECTORY,
PIDL);
SHGetPathFromIDList(PIDL,
StartupDirectory);
LinkFilename := StartupDirectory + '\MyNotepad.lnk';
tmpPFile.Save(pWChar(LinkFilename),FALSE);
end;