楼主可以查看 Inno Setup 帮助文件中关于函数 GetWindowsVersionEx 的用法。
Pascal 脚本: GetWindowsVersionEx
语法:
procedure GetWindowsVersionEx(var Version: TWindowsVersion);
描述:
返回记录中有关 Windows 版本的扩展信息。
TWindowsVersion 定义为:
TWindowsVersion = record
Major: Cardinal; // 主版本号
Minor: Cardinal; // 副版本号
Build: Cardinal; // 构建号
ServicePackMajor: Cardinal; // 服务包主版本号
ServicePackMinor: Cardinal; // 服务包副版本号
NTPlatform: Boolean; // 如果是基于 NT 平台则为 True
ProductType: Byte; // 产品类型 (看下面)
SuiteMask: Word; // 安装的产品组件 (看下面)
end;
ProductType 对象可以是下列值中的一个:
VER_NT_WORKSTATION
VER_NT_DOMAIN_CONTROLLER
VER_NT_SERVER
如果产品类型不能确定 (不一定可用),它也可以是零。VER_NT_WORKSTATION 表示非服务器版本的 Windows (例如工作站、专业版或家庭版)。
SuiteMask 对象可以是下列值的组合:
VER_SUITE_BACKOFFICE
VER_SUITE_BLADE
VER_SUITE_DATACENTER
VER_SUITE_ENTERPRISE
VER_SUITE_EMBEDDEDNT
VER_SUITE_PERSONAL
VER_SUITE_SINGLEUSERTS
VER_SUITE_SMALLBUSINESS
VER_SUITE_SMALLBUSINESS_RESTRICTED
VER_SUITE_TERMINAL
VER_SUITE_PERSONAL 设置在比如家庭版的 Windows XP,VER_SUITE_BLADE 设置在网络版的 Windows Server 2003。
示例:
下面的例子告诉你可以怎样在某些版本的 Windows 中不接受安装,并在多个操作系统版梧检查服务包等级。(这些内容都不可能用 [Setup] 段 MinVersion 指令。)
function InitializeSetup: Boolean;
var
Version: TWindowsVersion;
S: String;
begin
GetWindowsVersionEx(Version);
// 不接受在家庭版的 Windows 中安装
if Version.SuiteMask and VER_SUITE_PERSONAL <> 0 then
begin
SuppressibleMsgBox('这个程序不能安装于家庭版的 Windows。',
mbCriticalError, MB_OK, MB_OK);
Result := False;
Exit;
end;
// 不接受在域控制器中安装
if Version.ProductType = VER_NT_DOMAIN_CONTROLLER then
begin
SuppressibleMsgBox('这个程序不能安装于域控制器。',
mbCriticalError, MB_OK, MB_OK);
Result := False;
Exit;
end;
// 在 Windows 2000,检查 SP4
if Version.NTPlatform and
(Version.Major = 5) and
(Version.Minor = 0) and
(Version.ServicePackMajor < 4) then
begin
SuppressibleMsgBox('在 Windows 2000 运行时,必须安装 Service Pack 4。',
mbCriticalError, MB_OK, MB_OK);
Result := False;
Exit;
end;
// 在 Windows XP 中,检查 SP2
if Version.NTPlatform and
(Version.Major = 5) and
(Version.Minor = 1) and
(Version.ServicePackMajor < 2) then
begin
SuppressibleMsgBox('在 Windows XP 运行时,必须安装 Service Pack 2。',
mbCriticalError, MB_OK, MB_OK);
Result := False;
Exit;
end;
Result := True;
end;