windows - 在 Inno Setup 中确定 Windows 版本

标签 windows inno-setup pascalscript

我正在使用 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.dllshell32.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/

相关文章:

inno-setup - 从 Inno Setup [代码] 中拆卸字符串

c++ - 创建过程不起作用

c++ - 从配置为生成 DLL 的 visual studio 项目创建 lib 文件

inno-setup - Inno Setup - 安装软件的文件夹、开始菜单文件夹、桌面图标都在同一页面中

inno-setup - 创新设置: Disable finish page

regex - Inno Setup 中字符串的正则表达式

windows - 如何在 Pascal Script/Inno Setup 中使用 WinAPI 中的 PathCombine()?

Java JACOB 检索给定 Win32_* 类对象的所有属性

windows - 在 Windows 上链接到 libjpeg 时如何解析 "undefined reference"?

inno-setup - 使用 inno-setup 在用户 AppData 文件夹中安装文件