InnoSetup:根据Installer中的值在Common / User Desktop中生成图标

时间:2013-11-12 20:52:17

标签: installer install inno-setup pascal

我们在InnoSetup配置中提供了一个自定义向导页面,它为我们提供了InstallForAllUsers变量。根据此变量的值,我们希望将图标放置在适用于所有用户的Common Desktop / Common Startup位置,并将User Desktop / User Startup放置在当前用户的位置。< / p>

我们的图标部分如下所示:

[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"

如何在必要时利用我的InstallForAllUsers变量替换这些常量?

2 个答案:

答案 0 :(得分:4)

图标部分:

[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;

答案 1 :(得分:2)

您可以使用返回“所有用户”变量的Check:函数来控制是否创建了图标:

[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;

请注意,如果从受限用户帐户运行,{user*}常量很可能适用于与预期值不同的用户。这是“每用户”安装不再常见的主要原因。