How to remove a desktop shortcut by Innosetup

trudger picture trudger · Sep 6, 2009 · Viewed 9.1k times · Source

How can I remove a desktop shortcut by Innosetup? It's created by previous version and not needed anymore. I tried delete it in [InstallDelete]

[InstallDelete]
Type: files; Name: {userdesktop}\Shortcut Name

and delete the file in "ssInstall" of CurStepChanged event handler

DeleteFile(ExpandConstant('{userdesktop}\Shortcut Name'));

But they don't work. Any suggestion is appreciated!

Answer

Gerald picture Gerald · Sep 6, 2009

Either option will work, but there are a couple of considerations.

1) You'll either need to use {userdesktop} or {commondesktop} depending on whether the shortcut was installed for a specific user or for all users.

2) You'll need to make sure to add the .lnk extension to the shortcut name.

So this will probably work:

DeleteFile(ExpandConstant('{userdesktop}\Shortcut Name.lnk'));
DeleteFile(ExpandConstant('{commondesktop}\Shortcut Name.lnk'));

or

[InstallDelete]
Type: files; Name: "{userdesktop}\Shortcut Name.lnk"
Type: files; Name: "{commondesktop}\Shortcut Name.lnk"