inno-setup - 在 Inno Setup 中为不同版本的 Windows 创建图标并运行不同的程序
问题描述
我想在安装过程中使用代码变量来决定[Icons]
和[Run]
部分,但我不知道我是否错了。
我的[Code]
部分是:
[Code]
var
myW7Val: string;
function GetMyW7Val(Value: string): string;
begin
Result := myW7Val;
end;
function IsWindowsVersionOrNewer(Major, Minor: Integer): Boolean;
var
Version: TWindowsVersion;
begin
GetWindowsVersionEx(Version);
Result :=
(Version.Major > Major) or
((Version.Major = Major) and (Version.Minor >= Minor));
end;
function IsWindows8OrNewer: Boolean;
begin
Result := IsWindowsVersionOrNewer(6, 2);
if not Result then
myW7Val := '1';
myW7Val := '0';
end;
function InitializeSetup: Boolean;
begin
IsWindows8OrNewer
Result := True;
end;
我的[Icons]
部分是:
[Icons]
#if "{code:GetMyW7Val}" == '0'
Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; \
Tasks: desktopicon
Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\{#MyAppName}"; \
Filename: "{app}\{#MyAppExeName}"; Tasks: quicklaunchicon
#elif "{code:GetMyW7Val}" == '1'
Name: "{autoprograms}\{#MyAppLanceurName}"; \
Filename: "{app}\{#MyAppLanceurExeName}"
Name: "{autodesktop}\{#MyAppLanceurName}"; \
Filename: "{app}\{#MyAppLanceurExeName}"; Tasks: desktopicon
Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\{#MyAppLanceurName}"; \
Filename: "{app}\{#MyAppLanceurExeName}"; Tasks: quicklaunchicon
#endif
我想使用前三个条目 if myW7Val
is0
和其他 if myW7Val
is 1
。但目前我有一个错误,没有价值观。
你有什么想法?
提前致谢
解决方案
要回答您的字面问题,请使用Check
参数:
[Code]
function IsWindows8OrNewer: Boolean;
begin
Result := IsWindowsVersionOrNewer(6, 2);
end;
[Icons]
Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; \
Check: not IsWindows8OrNewer
Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; \
Tasks: desktopicon; Check: not IsWindows8OrNewer
Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\{#MyAppName}"; \
Filename: "{app}\{#MyAppExeName}"; Tasks: quicklaunchicon; \
Check: not IsWindows8OrNewer
Name: "{autoprograms}\{#MyAppLanceurName}"; \
Filename: "{app}\{#MyAppLanceurExeName}"; Check: IsWindows8OrNewer
Name: "{autodesktop}\{#MyAppLanceurName}"; \
Filename: "{app}\{#MyAppLanceurExeName}"; Tasks: desktopicon; \
Check: IsWindows8OrNewer
Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\{#MyAppLanceurName}"; \
Filename: "{app}\{#MyAppLanceurExeName}"; Tasks: quicklaunchicon; \
Check: IsWindows8OrNewer
虽然这有点过头了,但有一些MinVersion
参数OnlyBelowVersion
可以为特定 Windows 版本选择条目:
[Icons]
Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; \
OnlyBelowVersion: 6.2
Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; \
Tasks: desktopicon; OnlyBelowVersion: 6.2
Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\{#MyAppName}"; \
Filename: "{app}\{#MyAppExeName}"; Tasks: quicklaunchicon; \
OnlyBelowVersion: 6.2
Name: "{autoprograms}\{#MyAppLanceurName}"; \
Filename: "{app}\{#MyAppLanceurExeName}"; MinVersion: 6.2
Name: "{autodesktop}\{#MyAppLanceurName}"; \
Filename: "{app}\{#MyAppLanceurExeName}"; Tasks: desktopicon; \
MinVersion: 6.2
Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\{#MyAppLanceurName}"; \
Filename: "{app}\{#MyAppLanceurExeName}"; Tasks: quicklaunchicon; MinVersion: 6.2
或者,您可以使用脚本常量来选择应用程序名称和文件名,以避免重复Icons
条目:
[Code]
function IsWindows8OrNewer: Boolean;
begin
Result := IsWindowsVersionOrNewer(6, 2);
end;
function GetAppName(Param: string): string;
begin
if IsWindows8OrNewer then Result := '{#MyAppLanceurName}'
else Result := '{#MyAppName}';
end;
function GetAppExeName(Param: string): string;
begin
if IsWindows8OrNewer then Result := '{#MyAppLanceurExeName}'
else Result := '{#MyAppExeName}';
end;
[Icons]
Name: "{autoprograms}\{code:GetAppName}"; Filename: "{app}\{code:GetAppExeName}"
Name: "{autodesktop}\{code:GetAppName}"; Filename: "{app}\{code:GetAppExeName}"; \
Tasks: desktopicon
Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\{code:GetAppName}"; \
Filename: "{app}\{code:GetAppExeName}"; Tasks: quicklaunchicon
推荐阅读
- list - haskell中一些数字([1,1,1,1,1,1])的列表
- swift - SwiftUI Representable TextField 更改字体消失
- javascript - 我们可以在 .NetCore WebApi 中沿 c# 放置 JavaScript 代码吗
- javascript - 为什么我无法访问对象的属性?
- mysql - 服务器错误(RequestEntityTooLarge):请求实体太大:创建 configMap 时限制为 3145728
- yii2 - TCPDF 在一行之后跳过项目并仅打印一些数据行
- angular - 在两个同级组件之间交换引用
- sql - 删除操作间歇性减慢oracle 11g
- python - Plotly Dash:如何解决错误 dash_html_components.Div 检测到除子项以外的道具的组件
- postgresql - 提高 postgres 的性能