在 Inno Setup 中确定 Windows 版本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5849917/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Determine Windows version in Inno Setup
提问by wallyk
I'm using Inno Setup to change the recycle bin in the OS. I need to make some cases for if the user is running Windows 7 or Windows XP. I try using:
我正在使用 Inno Setup 更改操作系统中的回收站。如果用户运行的是 Windows 7 或 Windows XP,我需要做一些案例。我尝试使用:
if not FileExists(winDir + '\System32\imageres.dll') then
if not FileExists(winDir + '\System32\shell32.dll') then
installError(3);
But it seems like it can't find imageres.dll
or shell32.dll
even though I've verified they exist. What am I doing wrong? Or can I check the Windows version another way?
但它似乎无法找到,imageres.dll
或者shell32.dll
即使我已经验证它们存在。我究竟做错了什么?或者我可以通过其他方式检查 Windows 版本吗?
回答by Andreas Rejbrand
You should use the GetWindowsVersionEx
function. It fills a TWindowsVersion
record:
您应该使用该GetWindowsVersionEx
功能。它填写了一个TWindowsVersion
记录:
TWindowsVersion = record
Major: Cardinal; // Major version number
Minor: Cardinal; // Minor version number
Build: Cardinal; // Build number
ServicePackMajor: Cardinal; // Major version number of service pack
ServicePackMinor: Cardinal; // Minor version number of service pack
NTPlatform: Boolean; // True if an NT-based platform
ProductType: Byte; // Product type (see below)
SuiteMask: Word; // Product suites installed (see below)
end;
There are a lot of other related functions. See below 'System functions' at this page.
还有很多其他相关的功能。请参阅本页下方的“系统功能” 。
回答by Martin Prikryl
In most Inno Setup sections (like [Files]
, [Tasks]
, [Run]
, etc.) you can use the MinVersion
and OnlyBelowVersion
common parameters.
在大多数 Inno Setup 部分(如[Files]
、[Tasks]
、[Run]
等)中,您可以使用MinVersion
和OnlyBelowVersion
通用参数。
[Files]
Source: MyDllForVistaAndNewer.dll; Dest: {app}\MyDll.dll; MinVersion: 6.0
Source: MyDllForOldWindows.dll; Dest: {app}\MyDll.dll; OnlyBelowVersion: 6.0
In Pascal Script, use the GetWindowsVersionEx
function to find the Windows version number. Then compare the number against a specific Windows version number.
在 Pascal Script 中,使用该GetWindowsVersionEx
函数查找 Windows 版本号。然后将该数字与特定的Windows 版本号进行比较。
Here are few handy functions to check specific Windows versions:
这里有一些方便的功能来检查特定的 Windows 版本:
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 IsWindowsXPOrNewer: Boolean;
begin
Result := IsWindowsVersionOrNewer(5, 1);
end;
function IsWindowsVistaOrNewer: Boolean;
begin
Result := IsWindowsVersionOrNewer(6, 0);
end;
function IsWindows7OrNewer: Boolean;
begin
Result := IsWindowsVersionOrNewer(6, 1);
end;
function IsWindows8OrNewer: Boolean;
begin
Result := IsWindowsVersionOrNewer(6, 2);
end;
function IsWindows10OrNewer: Boolean;
begin
Result := IsWindowsVersionOrNewer(10, 0);
end;
Example of use:
使用示例:
function InitializeSetup: Boolean;
begin
if not IsWindowsVistaOrNewer then
begin
MsgBox(
'This program was not tested on Windows XP and older, proceed with caution.',
mbCriticalError, MB_OK);
end;
Result := True;
end;
To test for server-editions of Windows, see:
Checking for Windows Server 2003
要测试 Windows 的服务器版本,请参阅:
检查 Windows Server 2003
For version checking to work correctly on modern versions of Windows, make sure you always use the latest version of Inno Setup.
要在现代版本的 Windows 上正确进行版本检查,请确保始终使用最新版本的 Inno Setup。
回答by wallyk
According to the documentation, the parameters associated with each file can be directly tied to the OS version:
根据文档,与每个文件关联的参数可以直接绑定到操作系统版本:
[Files]
Source: "{app}\WinNT2000XP.exe"; DestDir: "{app}"; MinVersion: 0, 1
Source: "{app}\Win9598Me.exe"; DestDir: "{app}"; MinVersion: 1, 0
"0" means never install; "1" means install on any version (i.e. version 1.0 or later).
“0”表示从不安装;“1”表示安装在任何版本上(即版本 1.0 或更高版本)。
Note: The above technique isn't limited to the [Files] section; MinVersion and OnlyBelowVersion can be used in most sections.
注意:上述技术不仅限于 [Files] 部分;MinVersion 和 OnlyBelowVersion 可用于大多数部分。