inno setup判断是Windows系统版本

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 中不接受安装,并在多个操作系统版梧检查服务包等级。

    代码

[Code]
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 
= 5and
     (Version.Minor 
= 0and
     (Version.ServicePackMajor 
< 4then
  
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 
= 5and
     (Version.Minor 
= 1and
     (Version.ServicePackMajor 
< 2then
  
begin
    SuppressibleMsgBox(
'在 Windows XP 运行时,必须安装 Service Pack 2。',
      mbCriticalError, MB_OK, MB_OK);
    Result :
= False;
    Exit;
  
end;

  Result :
= True;
end

 

 

posted @ 2011-01-22 14:35  Day_Dreamer  阅读(3582)  评论(0编辑  收藏  举报