2

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

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

[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变量替换这些常量?

4

2 回答 2

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;
于 2013-11-12T21:09:38.860 回答
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*}如果从受限用户帐户运行,这些常量很可能适用于与预期不同的用户。这是“按用户”安装不再常见的主要原因。

于 2013-11-13T14:34:40.573 回答