23

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!

mghie
  • 31,678
  • 6
  • 85
  • 125
trudger
  • 907
  • 1
  • 12
  • 20
  • You can remove *all* old icons from previous versions safely using this method: http://stackoverflow.com/a/22568945/32453 – rogerdpack May 05 '14 at 23:29

1 Answers1

34

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"
Gerald
  • 22,593
  • 10
  • 68
  • 100
  • 2
    Altought I installed the link with Name: "{commondesktop}\..., the above solutions for deleting it didn't work for me and I had to fall back to Type: files; Name: "C:\Users\Public\Desktop\My App.lnk" as a work around. – transistor Apr 07 '17 at 08:49