Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit GetWinVersionInfo;
- interface
- function GetOSInfo: string;
- implementation
- uses
- SysUtils, Windows, Registry;
- function GetVersionExA(var lpVersionInformation: TOSVersionInfoEX): BOOL;
- stdcall; external kernel32;
- var
- GetProductInfo: function (dwOSMajorVersion, dwOSMinorVersion,
- dwSpMajorVersion, dwSpMinorVersion: DWORD;
- var pdwReturnedProductType: DWORD): BOOL stdcall = NIL;
- function GetOSInfo: string;
- var
- NTBres, BRes: Boolean;
- OSVI: TOSVERSIONINFO;
- OSVI_NT: TOSVERSIONINFOEX;
- tmpStr: string;
- dwOSMajorVersion, dwOSMinorVersion,
- dwSpMajorVersion, dwSpMinorVersion,
- pdwReturnedProductType : DWORD;
- begin
- Result := 'Error';
- NTBRes := FALSE;
- try
- OSVI_NT.dwOSVersionInfoSize := SizeOf(TOSVERSIONINFOEX);
- NTBRes := GetVersionExA(OSVI_NT);
- OSVI.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);
- BRes := GetVersionEx(OSVI);
- except
- OSVI.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);
- BRes := GetVersionEx(OSVI);
- end;
- if (not BRes) and (not NTBres) then
- Exit;
- Move( OSVI, OSVI_NT, SizeOf(TOSVersionInfo) );
- case OSVI_NT.dwPlatformId of
- VER_PLATFORM_WIN32_NT:
- begin
- if OSVI_NT.dwMajorVersion <= 4 then
- Result := 'Windows NT '
- else if (OSVI_NT.dwMajorVersion = 5) and (OSVI_NT.dwMinorVersion = 0) then
- Result := 'Windows 2000 '
- else if (OSVI_NT.dwMajorVersion = 5) and (OSVI_NT.dwMinorVersion = 1) then
- Result := 'Windows XP '
- else if (OSVI_NT.dwMajorVersion >= 6) then
- begin
- if (OSVI_NT.dwMajorVersion=6) and (OSVI_NT.dwMinorVersion = 0) then
- Result := 'Windows Vista '
- else if (OSVI_NT.dwMajorVersion=6) and (OSVI_NT.dwMinorVersion = 1) then
- Result := 'Windows 7 '
- else if (OSVI_NT.dwMajorVersion=6) and (OSVI_NT.dwMinorVersion = 1) then
- Result := 'Windows 8 '
- else
- Result := 'Windows ';
- if Assigned(GetProductInfo) then
- begin
- dwOSMajorVersion := 6;
- dwOSMinorVersion := 0;
- dwSpMajorVersion := 0;
- dwSpMinorVersion := 0;
- GetProductInfo( dwOSMajorVersion, dwOSMinorVersion,
- dwSpMajorVersion, dwSpMinorVersion,
- pdwReturnedProductType );
- case pdwReturnedProductType of
- PRODUCT_BUSINESS:
- tmpStr := 'Business Edition';
- PRODUCT_BUSINESS_N:
- tmpStr := 'Business Edition';
- PRODUCT_CLUSTER_SERVER:
- tmpStr := 'Cluster Server Edition';
- PRODUCT_DATACENTER_SERVER:
- tmpStr := 'Server Datacenter Edition (full installation)';
- PRODUCT_DATACENTER_SERVER_CORE:
- tmpStr := 'Server Datacenter Edition (core installation)';
- PRODUCT_ENTERPRISE:
- tmpStr := 'Enterprise Edition';
- PRODUCT_ENTERPRISE_N:
- tmpStr := 'Enterprise Edition';
- PRODUCT_ENTERPRISE_SERVER:
- tmpStr := 'Server Enterprise Edition (full installation)';
- PRODUCT_ENTERPRISE_SERVER_CORE:
- tmpStr := 'Server Enterprise Edition (core installation)';
- PRODUCT_ENTERPRISE_SERVER_IA64:
- tmpStr := 'Server Enterprise Edition for Itanium-based Systems';
- PRODUCT_HOME_BASIC:
- tmpStr := 'Home Basic Edition';
- PRODUCT_HOME_BASIC_N:
- tmpStr := 'Home Basic Edition';
- PRODUCT_HOME_PREMIUM:
- tmpStr := 'Home Premium Edition';
- PRODUCT_HOME_PREMIUM_N:
- tmpStr := 'Home Premium Edition';
- PRODUCT_HOME_SERVER:
- tmpStr := 'Home Server Edition';
- PRODUCT_SERVER_FOR_SMALLBUSINESS:
- tmpStr := 'Server for Small Business Edition';
- PRODUCT_SMALLBUSINESS_SERVER:
- tmpStr := 'Small Business Server';
- PRODUCT_SMALLBUSINESS_SERVER_PREMIUM:
- tmpStr := 'Small Business Server Premium Edition';
- PRODUCT_STANDARD_SERVER:
- tmpStr := 'Server Standard Edition (full installation)';
- PRODUCT_STANDARD_SERVER_CORE:
- tmpStr := 'Server Standard Edition (core installation)';
- PRODUCT_STARTER:
- tmpStr := 'Starter Edition';
- PRODUCT_STORAGE_ENTERPRISE_SERVER:
- tmpStr := 'Storage Server Enterprise Edition';
- PRODUCT_STORAGE_EXPRESS_SERVER:
- tmpStr := 'Storage Server Express Edition';
- PRODUCT_STORAGE_STANDARD_SERVER:
- tmpStr := 'Storage Server Standard Edition';
- PRODUCT_STORAGE_WORKGROUP_SERVER:
- tmpStr := 'Storage Server Workgroup Edition';
- PRODUCT_UNDEFINED:
- tmpStr := 'An unknown product';
- PRODUCT_ULTIMATE:
- tmpStr := 'Ultimate Edition';
- PRODUCT_ULTIMATE_N:
- tmpStr := 'Ultimate Edition';
- PRODUCT_WEB_SERVER:
- tmpStr := 'Web Server Edition';
- PRODUCT_UNLICENSED:
- tmpStr := 'Unlicensed product'
- else
- tmpStr := '';
- end;{ pdwReturnedProductType }
- Result := Result + tmpStr;
- NTBRes := FALSE;
- end;{ GetProductInfo<>NIL }
- end;{ Vista }
- if NTBres then
- begin
- if OSVI_NT.wProductType = VER_NT_WORKSTATION then
- begin
- if OSVI_NT.wProductType = VER_NT_WORKSTATION then
- begin
- case OSVI_NT.wSuiteMask of
- 512: Result := Result + 'Personal';
- 768: Result := Result + 'Home Premium';
- else
- Result := Result + 'Professional';
- end;
- end
- else if OSVI_NT.wProductType = VER_NT_SERVER then
- begin
- if OSVI_NT.wSuiteMask = VER_SUITE_DATACENTER then
- Result := Result + 'DataCenter Server'
- else if OSVI_NT.wSuiteMask = VER_SUITE_ENTERPRISE then
- Result := Result + 'Advanced Server'
- else
- Result := Result + 'Server';
- end;
- end{ wProductType=VER_NT_WORKSTATION }
- else
- begin
- with TRegistry.Create do
- try
- RootKey := HKEY_LOCAL_MACHINE;
- if OpenKeyReadOnly('SYSTEM\CurrentControlSet\Control\ProductOptions') then
- try
- tmpStr := UpperCase(ReadString('ProductType'));
- if tmpStr = 'WINNT' then
- Result := Result + 'Workstation';
- if tmpStr = 'SERVERNT' then
- Result := Result + 'Server';
- finally
- CloseKey;
- end;
- finally
- Free;
- end;
- end;{ wProductType<>VER_NT_WORKSTATION }
- end;{ NTBRes }
- end;{ VER_PLATFORM_WIN32_NT }
- VER_PLATFORM_WIN32_WINDOWS:
- begin
- if (OSVI.dwMajorVersion = 4) and (OSVI.dwMinorVersion = 0) then
- begin
- Result := 'Windows 95 ';
- if OSVI.szCSDVersion[1] = 'C' then
- Result := Result + 'OSR2';
- end;
- if (OSVI.dwMajorVersion = 4) and (OSVI.dwMinorVersion = 10) then
- begin
- Result := 'Windows 98 ';
- if OSVI.szCSDVersion[1] = 'A' then
- Result := Result + 'SE';
- end;
- if (OSVI.dwMajorVersion = 4) and (OSVI.dwMinorVersion = 90) then
- Result := 'Windows Me';
- end;{ VER_PLATFORM_WIN32_WINDOWS }
- VER_PLATFORM_WIN32s:
- Result := 'Microsoft Win32s';
- else
- Result := 'Unknown';
- end;{ OSVI_NT.dwPlatformId }
- end;{ GetOSInfo }
- initialization
- @GetProductInfo := GetProcAddress(GetModuleHandle('KERNEL32.DLL'),
- 'GetProductInfo');
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement