我正在使用 Inno Setup 更改操作系统中的回收站。如果用户运行的是 Windows 7 或 Windows XP,我需要做一些案例。我尝试使用:
if not FileExists(winDir + '\System32\imageres.dll') then
if not FileExists(winDir + '\System32\shell32.dll') then
installError(3);
但它似乎找不到 imageres.dll
或 shell32.dll
,即使我已经验证它们存在。我究竟做错了什么?或者我可以通过其他方式检查 Windows 版本吗?
最佳答案
在大多数 Inno Setup 部分(如 [Files]
、[Tasks]
、[Run]
等),您可以使用MinVersion
and OnlyBelowVersion
common parameters .
[Files]
Source: MyDllForVistaAndNewer.dll; Dest: {app}\MyDll.dll; MinVersion: 6.0
Source: MyDllForOldWindows.dll; Dest: {app}\MyDll.dll; OnlyBelowVersion: 6.0
在 Pascal 脚本中,使用 GetWindowsVersionEx
查找 Windows 版本号的函数。然后将数字与特定的 Windows version number 进行比较.
这里有几个方便的函数来检查特定的 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;
// Windows 11 has the same major.minor as Windows 10.
// So it has to be distinguished by the Build.
// The IsWindows10OrNewer condition is actually redundant.
// Once we have to test for Windows 11 using the build number, we could actually
// unify and simplify all the tests above to use the build numbers only too.
function IsWindows11OrNewer: Boolean;
var
Version: TWindowsVersion;
begin
GetWindowsVersionEx(Version);
Result := IsWindows10OrNewer and (Version.Build >= 22000);
end;
使用示例:
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;
要测试服务器版本的 Windows,请参阅:
Checking for Windows Server 2003
要使版本检查在现代版本的 Windows 上正常工作,请确保您始终使用最新版本的 Inno Setup。
关于windows - 在 Inno Setup 中确定 Windows 版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5849917/