2

We provide a custom Wizard page in our InnoSetup configuration that gives us an InstallForAllUsers variable. Based on the value of this variable, we want to place our icons in the appropriate places Common Desktop/Common Startup for All Users, and User Desktop/User Startup for Current User.

Our Icons section looks like this:

[Icons]
Name: "{group}\MyApp"; Filename: "{app}\MyApp.exe"; IconFilename: "{app}\MyApp.exe"
Name: "{group}\{cm:UninstallProgram,MyApp}"; Filename: "{uninstallexe}"; IconFilename: E:\Continuous Integration\InnoSetup Files\icon.ico
Name: "{commondesktop}\MyApp"; Filename: "{app}\MyApp.exe"; IconFilename: "{app}\MyApp.exe"
Name: "{commonstartup}\MyApp"; Filename: "{app}\MyApp.exe"; IconFilename:  "{app}\MyApp.exe"

How can I leverage my InstallForAllUsers variable to replace these constants when necessary?

DTI-Matt
  • 2,065
  • 9
  • 35
  • 60
  • 1
    Look at [`this post`](http://stackoverflow.com/a/19757381/960757) for instance. It should be applicable to your case as well. – TLama Nov 12 '13 at 21:00
  • This is exactly what I did since I used a similar thing for my Registry keys. Posting an answer right now. Thanks for the link though! – DTI-Matt Nov 12 '13 at 21:05
  • 1
    Generally speaking, it is better to remove this choice from the UI than to try to implement it. Changing where the icon goes does not make the difference between a per-user or per-machine install. – Miral Nov 13 '13 at 09:02

2 Answers2

4

Icons Section:

[Icons]    
Name: "{group}\MyApp"; Filename: "{app}\MyApp.exe"; IconFilename: "{app}\MyApp.exe"
Name: "{group}\{cm:UninstallProgram,MyApp}"; Filename: "{uninstallexe}"; IconFilename: E:\Continuous Integration\InnoSetup Files\icon.ico
Name: "{code:GetDesktopFolder}\MyApp"; Filename: "{app}\MyApp.exe"; IconFilename: "{app}\MyApp.exe"
Name: "{code:GetStartupFolder}\MyApp"; Filename: "{app}\MyApp.exe"; IconFilename:  "{app}\MyApp.exe"

Code:

function GetDesktopFolder(Param: String): String;
begin
  if (InstallAllUsers) then
    Result := ExpandConstant('{commondesktop}')
  else
    Result := ExpandConstant('{userdesktop}');
end;

function GetStartupFolder(Param: String): String;
begin
  if (InstallAllUsers) then
    Result := ExpandConstant('{commonstartup}')
  else
    Result := ExpandConstant('{userstartup}');
end;
DTI-Matt
  • 2,065
  • 9
  • 35
  • 60
2

You can use a Check: function that returns the "all users" variable to control whether the icon is created or not:

[Icons]
Name: "{commondesktop}\MyApp"; Filename: "{app}\MyApp.exe"; IconFilename: "{app}\MyApp.exe"; Check: Not CheckPerUserInstall;
Name: "{userdesktop}\MyApp"; Filename: "{app}\MyApp.exe"; IconFilename: "{app}\MyApp.exe"; Check: CheckPerUserInstall;
Name: "{commonstartup}\MyApp"; Filename: "{app}\MyApp.exe"; IconFilename:  "{app}\MyApp.exe"; Check: Not CheckPerUserInstall;
Name: "{userstartup}\MyApp"; Filename: "{app}\MyApp.exe"; IconFilename:  "{app}\MyApp.exe"; Check: CheckPerUserInstall;

[Code]
function CheckPerUserInstall(): Boolean;
begin
  Result := InstallForAllUsers;
end;

Note that the {user*} constants may very well be for a different user to the expected one if run from a limited user account. This is the primary reason why "per user" installs aren't that common anymore.

Deanna
  • 23,876
  • 7
  • 71
  • 156