Programmatically create desktop icon with InnoSetup

Posted on January 17, 2021 at 6:29 pm

Inside “ssPostInstall” of CurStepChanged() add this code:

//create user desktop shortcut
ShortcutPath := ExpandConstant('{userdesktop}') + '\YourApp.lnk';
CreateShellLink(ShortcutPath, 'YourApp', ExpandConstant('{app}\YourApp.exe'), '', ExpandConstant('{app}'), '', 0, SW_SHOWNORMAL);

If you want to disable desktop icon via command-line, use this:

if ExpandConstant('{param:skipdesktopicon|false}') <> 'false' then
begin
//create user desktop shortcut
ShortcutPath := ExpandConstant('{userdesktop}') + '\YourApp.lnk';
CreateShellLink(ShortcutPath, 'YourApp', ExpandConstant('{app}\YourApp.exe'), '', ExpandConstant('{app}'), '', 0, SW_SHOWNORMAL);
end;

To not add desktop icon just run the setup.exe like this:

setup.exe /skipdesktopicon=true

Then inside “usPostUninstall” of CurUninstallStepChanged() add this code:

//Delete desktop shortcut icon (custom created)
DeleteFile(ExpandConstant('{userdesktop}') + '\YourApp.lnk');

References:

https://stackoverflow.com/a/35225666
https://jrsoftware.org/ishelp/index.php?topic=isxfunc_createshelllink

Receive updates via email

Other Posts

Updated Posts