Reputation: 2145
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?
Upvotes: 2
Views: 5109
Reputation: 24283
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.
Upvotes: 2
Reputation: 2145
[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"
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;
Upvotes: 4