Advertisement
Guest User

Untitled

a guest
Mar 28th, 2013
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 8.28 KB | None | 0 0
  1. unit GetWinVersionInfo;
  2.  
  3. interface
  4.  
  5. function GetOSInfo: string;
  6.  
  7. implementation
  8.  
  9. uses
  10.   SysUtils, Windows, Registry;
  11.  
  12. function GetVersionExA(var lpVersionInformation: TOSVersionInfoEX): BOOL;
  13.   stdcall; external kernel32;
  14.  
  15. var
  16.   GetProductInfo: function (dwOSMajorVersion, dwOSMinorVersion,
  17.                             dwSpMajorVersion, dwSpMinorVersion: DWORD;
  18.                             var pdwReturnedProductType: DWORD): BOOL stdcall = NIL;
  19.  
  20. function GetOSInfo: string;
  21. var
  22.   NTBres, BRes: Boolean;
  23.   OSVI: TOSVERSIONINFO;
  24.   OSVI_NT: TOSVERSIONINFOEX;
  25.   tmpStr: string;
  26.   dwOSMajorVersion, dwOSMinorVersion,
  27.   dwSpMajorVersion, dwSpMinorVersion,
  28.   pdwReturnedProductType : DWORD;
  29. begin
  30.   Result := 'Error';
  31.   NTBRes := FALSE;
  32.   try
  33.     OSVI_NT.dwOSVersionInfoSize := SizeOf(TOSVERSIONINFOEX);
  34.     NTBRes := GetVersionExA(OSVI_NT);
  35.     OSVI.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);
  36.     BRes := GetVersionEx(OSVI);
  37.   except
  38.     OSVI.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);
  39.     BRes := GetVersionEx(OSVI);
  40.   end;
  41.   if (not BRes) and (not NTBres) then
  42.     Exit;
  43.   Move( OSVI, OSVI_NT, SizeOf(TOSVersionInfo) );
  44.  
  45.   case OSVI_NT.dwPlatformId of
  46.      VER_PLATFORM_WIN32_NT:
  47.        begin
  48.          if OSVI_NT.dwMajorVersion <= 4 then
  49.            Result := 'Windows NT '
  50.          else if (OSVI_NT.dwMajorVersion = 5) and (OSVI_NT.dwMinorVersion = 0) then
  51.            Result := 'Windows 2000 '
  52.          else if  (OSVI_NT.dwMajorVersion = 5) and (OSVI_NT.dwMinorVersion = 1) then
  53.            Result := 'Windows XP '
  54.          else if (OSVI_NT.dwMajorVersion >= 6) then
  55.          begin
  56.            if (OSVI_NT.dwMajorVersion=6) and (OSVI_NT.dwMinorVersion = 0) then
  57.              Result := 'Windows Vista '
  58.            else if (OSVI_NT.dwMajorVersion=6) and (OSVI_NT.dwMinorVersion = 1) then
  59.              Result := 'Windows 7 '
  60.            else if (OSVI_NT.dwMajorVersion=6) and (OSVI_NT.dwMinorVersion = 1) then
  61.              Result := 'Windows 8 '
  62.            else
  63.              Result := 'Windows ';
  64.            if Assigned(GetProductInfo) then
  65.            begin
  66.              dwOSMajorVersion := 6;
  67.              dwOSMinorVersion := 0;
  68.              dwSpMajorVersion := 0;
  69.              dwSpMinorVersion := 0;
  70.              GetProductInfo( dwOSMajorVersion, dwOSMinorVersion,
  71.                              dwSpMajorVersion, dwSpMinorVersion,
  72.                              pdwReturnedProductType );
  73.              case pdwReturnedProductType of
  74.                PRODUCT_BUSINESS:
  75.                  tmpStr := 'Business Edition';
  76.                PRODUCT_BUSINESS_N:
  77.                  tmpStr := 'Business Edition';
  78.                PRODUCT_CLUSTER_SERVER:
  79.                  tmpStr := 'Cluster Server Edition';
  80.                PRODUCT_DATACENTER_SERVER:
  81.                  tmpStr := 'Server Datacenter Edition (full installation)';
  82.                PRODUCT_DATACENTER_SERVER_CORE:
  83.                  tmpStr := 'Server Datacenter Edition (core installation)';
  84.                PRODUCT_ENTERPRISE:
  85.                  tmpStr := 'Enterprise Edition';
  86.                PRODUCT_ENTERPRISE_N:
  87.                  tmpStr := 'Enterprise Edition';
  88.                PRODUCT_ENTERPRISE_SERVER:
  89.                  tmpStr := 'Server Enterprise Edition (full installation)';
  90.                PRODUCT_ENTERPRISE_SERVER_CORE:
  91.                  tmpStr := 'Server Enterprise Edition (core installation)';
  92.                PRODUCT_ENTERPRISE_SERVER_IA64:
  93.                  tmpStr := 'Server Enterprise Edition for Itanium-based Systems';
  94.                PRODUCT_HOME_BASIC:
  95.                  tmpStr := 'Home Basic Edition';
  96.                PRODUCT_HOME_BASIC_N:
  97.                  tmpStr := 'Home Basic Edition';
  98.                PRODUCT_HOME_PREMIUM:
  99.                  tmpStr := 'Home Premium Edition';
  100.                PRODUCT_HOME_PREMIUM_N:
  101.                  tmpStr := 'Home Premium Edition';
  102.                PRODUCT_HOME_SERVER:
  103.                  tmpStr := 'Home Server Edition';
  104.                PRODUCT_SERVER_FOR_SMALLBUSINESS:
  105.                  tmpStr := 'Server for Small Business Edition';
  106.                PRODUCT_SMALLBUSINESS_SERVER:
  107.                  tmpStr := 'Small Business Server';
  108.                PRODUCT_SMALLBUSINESS_SERVER_PREMIUM:
  109.                  tmpStr := 'Small Business Server Premium Edition';
  110.                PRODUCT_STANDARD_SERVER:
  111.                  tmpStr := 'Server Standard Edition (full installation)';
  112.                PRODUCT_STANDARD_SERVER_CORE:
  113.                  tmpStr := 'Server Standard Edition (core installation)';
  114.                PRODUCT_STARTER:
  115.                  tmpStr := 'Starter Edition';
  116.                PRODUCT_STORAGE_ENTERPRISE_SERVER:
  117.                  tmpStr := 'Storage Server Enterprise Edition';
  118.                PRODUCT_STORAGE_EXPRESS_SERVER:
  119.                  tmpStr := 'Storage Server Express Edition';
  120.                PRODUCT_STORAGE_STANDARD_SERVER:
  121.                  tmpStr := 'Storage Server Standard Edition';
  122.                PRODUCT_STORAGE_WORKGROUP_SERVER:
  123.                  tmpStr := 'Storage Server Workgroup Edition';
  124.                PRODUCT_UNDEFINED:
  125.                  tmpStr := 'An unknown product';
  126.                PRODUCT_ULTIMATE:
  127.                  tmpStr := 'Ultimate Edition';
  128.                PRODUCT_ULTIMATE_N:
  129.                  tmpStr := 'Ultimate Edition';
  130.                PRODUCT_WEB_SERVER:
  131.                  tmpStr := 'Web Server Edition';
  132.                PRODUCT_UNLICENSED:
  133.                  tmpStr := 'Unlicensed product'
  134.              else
  135.                tmpStr := '';
  136.              end;{ pdwReturnedProductType }
  137.              Result := Result + tmpStr;
  138.              NTBRes := FALSE;
  139.            end;{ GetProductInfo<>NIL }
  140.          end;{ Vista }
  141.          if NTBres then
  142.          begin
  143.            if OSVI_NT.wProductType = VER_NT_WORKSTATION then
  144.            begin
  145.              if OSVI_NT.wProductType = VER_NT_WORKSTATION then
  146.              begin
  147.                case OSVI_NT.wSuiteMask of
  148.                  512: Result := Result + 'Personal';
  149.                  768: Result := Result + 'Home Premium';
  150.                else
  151.                  Result := Result + 'Professional';
  152.                end;
  153.              end
  154.              else if OSVI_NT.wProductType = VER_NT_SERVER then
  155.              begin
  156.                if OSVI_NT.wSuiteMask = VER_SUITE_DATACENTER then
  157.                  Result := Result + 'DataCenter Server'
  158.                else if OSVI_NT.wSuiteMask = VER_SUITE_ENTERPRISE then
  159.                  Result :=  Result + 'Advanced Server'
  160.                else
  161.                  Result := Result + 'Server';
  162.              end;
  163.            end{ wProductType=VER_NT_WORKSTATION }
  164.            else
  165.            begin
  166.              with TRegistry.Create do
  167.                try
  168.                  RootKey := HKEY_LOCAL_MACHINE;
  169.                  if OpenKeyReadOnly('SYSTEM\CurrentControlSet\Control\ProductOptions') then
  170.                    try
  171.                      tmpStr := UpperCase(ReadString('ProductType'));
  172.                      if tmpStr = 'WINNT' then
  173.                        Result := Result + 'Workstation';
  174.                      if tmpStr = 'SERVERNT' then
  175.                        Result := Result + 'Server';
  176.                    finally
  177.                      CloseKey;
  178.                    end;
  179.                finally
  180.                  Free;
  181.                end;
  182.              end;{ wProductType<>VER_NT_WORKSTATION }
  183.            end;{ NTBRes }
  184.          end;{ VER_PLATFORM_WIN32_NT }
  185.      VER_PLATFORM_WIN32_WINDOWS:
  186.        begin
  187.          if (OSVI.dwMajorVersion = 4) and (OSVI.dwMinorVersion = 0) then
  188.          begin
  189.            Result := 'Windows 95 ';
  190.            if OSVI.szCSDVersion[1] = 'C' then
  191.              Result := Result + 'OSR2';
  192.          end;
  193.          if (OSVI.dwMajorVersion = 4) and (OSVI.dwMinorVersion = 10) then
  194.          begin
  195.            Result := 'Windows 98 ';
  196.            if OSVI.szCSDVersion[1] = 'A' then
  197.              Result := Result + 'SE';
  198.          end;
  199.          if (OSVI.dwMajorVersion = 4) and (OSVI.dwMinorVersion = 90) then
  200.            Result := 'Windows Me';
  201.        end;{ VER_PLATFORM_WIN32_WINDOWS }
  202.      VER_PLATFORM_WIN32s:
  203.        Result := 'Microsoft Win32s';
  204.   else
  205.     Result := 'Unknown';
  206.   end;{ OSVI_NT.dwPlatformId }
  207. end;{ GetOSInfo }
  208.  
  209. initialization
  210.    @GetProductInfo := GetProcAddress(GetModuleHandle('KERNEL32.DLL'),
  211.                                      'GetProductInfo');
  212.  
  213. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement