Serega0675
Member | Редактировать | Профиль | Сообщение | ICQ | Цитировать | Сообщить модератору Код: function CompareWindowsVersion(const Version: TWindowsVersion; WinVer: string): Integer; { Данная функция сравнивает версию Windows указанную в Version с версией указанной в WinVer Возвращаемые значения: -2: ошибка при разборе строки WinVer, т.е. формат задан не правильно; -1: Version < WinVer; 0: Version = WinVer; 1: Version > WinVer; } var value, ver, sp: string; pos_simbol, count: Integer; Major, Minor, Build, ServicePack: Integer; parse: Boolean; begin Result := -2; parse := False; if WinVer <> '' then try count := 0; ServicePack := 0; value := WinVer; while value <> '' do begin pos_simbol := Pos('.', value); case pos_simbol > 0 of True : begin ver := Copy(value, 1, pos_simbol - 1); Delete(value, 1, pos_simbol); end; False: begin ver := value; SetLength(value, 0); end; end; count := count + 1; case count of 1: // Major case Length(ver) = 1 of True : Major := StrToInt(ver); False: Exit; end; 2, 3: // Minor and Build begin pos_simbol := Pos('sp', LowerCase(ver)); case pos_simbol > 0 of True : begin sp := Copy(ver, pos_simbol + 2, Length(ver) - pos_simbol - 1); SetLength(ver, pos_simbol-1); case count of 2: Minor := StrToInt(ver); 3: Build := StrToInt(ver); end; ServicePack := StrToInt(sp); end; False: case count of 2: Minor := StrToInt(ver); 3: Build := StrToInt(ver); end; end; end; end; end; parse := True; except Exit; end; if parse then begin case Version.Major = Major of True : case Version.Minor = Minor of True : case Version.Build = Build of True : case ServicePack = 0 of True : Result := 0; False: case Version.ServicePackMajor = ServicePack of True : Result := 0; False: case Version.ServicePackMajor > ServicePack of True : Result := 1; False: Result := -1; end; end; end; False: case Version.Build > Build of True : Result := 1; False: Result := -1; end; end; False: case Version.Minor > Minor of True : Result := 1; False: Result := -1; end; end; False: case Version.Major > Major of True : Result := 1; False: Result := -1; end; end; end; end; function CheckMinAndOnlyBelowVersion(const MinVersion, OnlyBelowVersion: string): Boolean; { Пример: CheckMinAndOnlyBelowVersion('5.1', '6.0'); Функция вернёт True, если версия системы не менее заданных параметров в MinVersion и менее чем в OnlyBelowVersion. Обрабатываемые форматы записей для MinVersion и OnlyBelowVersion: 5.0 5.0.2195 5.0sp4 5.0.2195sp4 , где sp4 - версия пакета обновления. Памятка из Справки: 5.0.2195 Windows 2000 5.1.2600 Windows XP или Windows XP 64-Bit Edition Version 2002 (Itanium) 5.2.3790 Windows Server 2003 или Windows XP x64 Edition (AMD64/EM64T) или Windows XP 64-Bit Edition Version 2003 (Itanium) 6.0.6000 Windows Vista 6.0.6001 Windows Vista с Service Pack 1 или Windows Server 2008 6.1.7600 Windows 7 или Windows Server 2008 R2 6.1.7601 Windows 7 с Service Pack 1 или Windows Server 2008 R2 с Service Pack 1 6.2.8400 Windows 8 Release Preview Обычно нет необходимости определить номера сборки (то есть, можно просто использовать "5.1" для Windows XP). } var Version: TWindowsVersion; begin GetWindowsVersionEx(Version); Result := (CompareWindowsVersion(Version, MinVersion) >= 0) and (CompareWindowsVersion(Version, OnlyBelowVersion) = -1); end; | | Всего записей: 226 | Зарегистр. 22-06-2008 | Отправлено: 16:39 11-09-2012 | Исправлено: Serega0675, 16:45 11-09-2012 |
|