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 = 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;