杉宫竹苑工作室

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 2724|回复: 0

Inno Setup 判断 Windows 系统版本

[复制链接]
发表于 2015-2-3 23:10:02 | 显示全部楼层 |阅读模式

正式会员享受无限制浏览网站功能和高速网盘下载,赶快加入本站吧!

您需要 登录 才可以下载或查看,没有账号?立即注册

x
1.设置Windows最低版本要求
   [Setup]: MinVersion
   格式: a.bb,c.dd,这里 a.bb 是 Windows 版本,c.dd 是 Windows NT 版本。  
   默认值: 4.0,4.0   
   描述:这个指令让你指定你的软件运行必须的 Windows 或 Windows NT 版本最小版本,要防止你的程序在 Windows 或 Windows NT 下运行,请在最小版本中的一个指定“0”。构建号和/或安全服务包级别可以包含在版本号中。如果用户系统不适合最小版本需求,安装程序将出现一个错误消息并退出。

2. 在code段判断系统版本
  语法: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               // 表示非服务器版本的 Windows (例如工作站、专业版或家庭版)
   VER_NT_DOMAIN_CONTROLLER
   VER_NT_SERVER
(如果用户运行于 Windows 95/98/Me,或产品类型不能确定,它也可以是零。)
SuiteMask 对象取值可以是下列值的组合:
   VER_SUITE_BACKOFFICE
   VER_SUITE_BLADE                       // 设置在网络版的 Windows Server 2003
   VER_SUITE_DATACENTER
   VER_SUITE_ENTERPRISE
   VER_SUITE_EMBEDDEDNT
   VER_SUITE_PERSONAL                  // 设置在比如家庭版的 Windows XP
   VER_SUITE_SINGLEUSERTS
   VER_SUITE_SMALLBUSINESS
   VER_SUITE_SMALLBUSINESS_RESTRICTED
   VER_SUITE_TERMINAL
  (在 Windows 95/98/Me 和 NT 4.0,SuiteMask 总是为零。)

3.实例
下面的例子告诉你可以怎样在某些版本的 Windows 中不接受安装,并在多个操作系统版梧检查服务包等级。

  1. function InitializeSetup: Boolean;
  2. var
  3.   Version: TWindowsVersion;
  4.   S: String;
  5. begin
  6.   GetWindowsVersionEx(Version);

  7.   // 不接受在家庭版的 Windows 中安装
  8.   if Version.SuiteMask and VER_SUITE_PERSONAL <> 0 then
  9.   begin
  10.     SuppressibleMsgBox('这个程序不能安装于家庭版的 Windows。',
  11.       mbCriticalError, MB_OK, MB_OK);
  12.     Result := False;
  13.     Exit;
  14.   end;

  15.   // 不接受在域控制器中安装
  16.   if Version.ProductType = VER_NT_DOMAIN_CONTROLLER then
  17.   begin
  18.     SuppressibleMsgBox('这个程序不能安装于域控制器。',
  19.       mbCriticalError, MB_OK, MB_OK);
  20.     Result := False;
  21.     Exit;
  22.   end;

  23.   // 在 Windows 2000,检查 SP4
  24.   if Version.NTPlatform and
  25.      (Version.Major = 5) and
  26.      (Version.Minor = 0) and
  27.      (Version.ServicePackMajor < 4) then
  28.   begin
  29.     SuppressibleMsgBox('在 Windows 2000 运行时,必须安装 Service Pack 4。',
  30.       mbCriticalError, MB_OK, MB_OK);
  31.     Result := False;
  32.     Exit;
  33.   end;

  34.   // 在 Windows XP 中,检查 SP2
  35.   if Version.NTPlatform and
  36.      (Version.Major = 5) and
  37.      (Version.Minor = 1) and
  38.      (Version.ServicePackMajor < 2) then
  39.   begin
  40.     SuppressibleMsgBox('在 Windows XP 运行时,必须安装 Service Pack 2。',
  41.       mbCriticalError, MB_OK, MB_OK);
  42.     Result := False;
  43.     Exit;
  44.   end;

  45.   Result := True;
  46. end;
复制代码

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|SgzyStudio

GMT+8, 2024-5-11 18:24 , Processed in 0.122430 second(s), 23 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表