各位好:    最近小弟在写一个取操作系统版本的程序时,发现InternetGetConnectedState在windows2000时取的SERVER和PRO的版本都是一样的,请问有何办法判断操作系统版本为win2k /win2k server?

解决方案 »

  1.   

    我觉得有两个办法。一个是读注册表,得找找资料看版本信息放在注册表哪个键里。
    另一个更简单的方法,读c:\boot.ini文件,不过这方法不一定可行
      

  2.   

    var
      ov : _OSVERSIONINFOA;
    begin
      ov.dwOSVersionInfoSize := sizeof(_OSVERSIONINFOA);  GetVersionEx(ov);
      showmessage(inttostr(ov.dwMajorVersion));
      showmessage(ov.szCSDVersion);
    end;详细说明可以参考msdn
      

  3.   

    错了
    应该用VerifyVersionInfo
      

  4.   

    To naughtyboy(重归起跑线):
        "VerifyVersionInfo"没有这个函数呀?
      

  5.   

    到msdn里面查一查详细帮助
    VerifyVersionInfo在kernel32.dll里面
      

  6.   

    #include <windows.h>
    #include <stdio.h>
    int main()
    {
       OSVERSIONINFOEX osvi;
       BOOL bOsVersionInfoEx;   // Try calling GetVersionEx using the OSVERSIONINFOEX structure.
       //
       // If that fails, try using the OSVERSIONINFO structure.   ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
       osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);   if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) )
       {
          // If OSVERSIONINFOEX doesn't work, try OSVERSIONINFO.      osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
          if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) ) 
             return FALSE;
       }   switch (osvi.dwPlatformId)
       {
          case VER_PLATFORM_WIN32_NT:      // Test for the product.         if ( osvi.dwMajorVersion <= 4 )
                printf("Microsoft Windows NT ");         if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 )
                printf ("Microsoft Windows 2000 ");         if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 )
                printf ("Whistler ");      // Test for product type.         if( bOsVersionInfoEx )
             {
                if ( osvi.wProductType == VER_NT_WORKSTATION )
                {
                   if( osvi.wSuiteMask & VER_SUITE_PERSONAL )
                      printf ( "Personal " );
                   else
                      printf ( "Professional " );
                }            else if ( osvi.wProductType == VER_NT_SERVER )
                {
                   if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
                      printf ( "DataCenter Server " );
                   else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
                      printf ( "Advanced Server " );
                   else
                      printf ( "Server " );
                }
             }
             else
             {
                HKEY hKey;
                char szProductType[80];
                DWORD dwBufLen;            RegOpenKeyEx( HKEY_LOCAL_MACHINE,
                   "SYSTEM\\CurrentControlSet\\Control\\ProductOptions",
                   0, KEY_QUERY_VALUE, &hKey );
                RegQueryValueEx( hKey, "ProductType", NULL, NULL,
                   (LPBYTE) szProductType, &dwBufLen);
                RegCloseKey( hKey );
                if ( lstrcmpi( "WINNT", szProductType) == 0 )
                   printf( "Workstation " );
                if ( lstrcmpi( "SERVERNT", szProductType) == 0 )
                   printf( "Server " );
             }      // Display version, service pack (if any), and build number.         if ( osvi.dwMajorVersion <= 4 )
             {
                printf ("version %d.%d %s (Build %d)\n",
                   osvi.dwMajorVersion,
                   osvi.dwMinorVersion,
                   osvi.szCSDVersion,
                   osvi.dwBuildNumber & 0xFFFF);
             }
             else
             { 
                printf ("%s (Build %d)\n",
                   osvi.szCSDVersion,
                   osvi.dwBuildNumber & 0xFFFF);
             }
             break;      case VER_PLATFORM_WIN32_WINDOWS:         if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0)
             {
                 printf ("Microsoft Windows 95 ");
                 if ( osvi.szCSDVersion[1] == 'C' )
                    printf("OSR2 " );
             }          if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10)
             {
                 printf ("Microsoft Windows 98 ");
                 if ( osvi.szCSDVersion[1] == 'A' )
                    printf("SE " );
             }          if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90)
             {
                 printf ("Microsoft Windows Me ");
             } 
             break;      case VER_PLATFORM_WIN32s:         printf ("Microsoft Win32s ");
             break;
       }
       return TRUE;
    }糊涂了,VerifyVersionInfo是验证,GetVersionEx是获得版本
    上面的程序是msdn里面带有的,另外可能需要声明如下
    #define VER_SUITE_PERSONAL 0x00000200
    因为winnt.h里面可能没有定义
      

  7.   

    To  naughtyboy(重归起跑线):
       小弟不太懂C的,另GetVersionEx不能区别win2kpro 和win2kServer的,真的没有人碰到这样的问题吗?
      

  8.   

    能区别
    OSVERSIONINFOEX 和 OSVERSIONINFO 是不同地
      

  9.   

    msdn里边有个非常详细的例子GetVersionEx(...)
      

  10.   

    各位:
        不好意思,小弟近日出差所以回复的慢.我测试的win2k pro 和 win2k server 取的版本号都是 windows 5.0 buld 2195 ,该如何判断,请各位大侠帮助!
      

  11.   

    搞定了
    文章】如何詳細辨識 OS 版本
    【作者】Chris Stone
    【內文】http://delphi.ktop.com.tw/topic.asp?topic_id=55607程式來源:http://www.swissdelphicenter.ch/torry/showcode.php?id=316
    {************************************************} 
    { Function to detect OS Version by Nico Bendlin  } 
    {************************************************} 
    {$IFDEF CONDITIONALEXPRESSIONS} 
      {$IF Defined(TOSVersionInfoEx)} 
        {$DEFINE TOSVERSIONINFOEX_DEFINED} 
      {$IFEND} 
    {$ENDIF} 
    {$IFNDEF TOSVERSIONINFOEX_DEFINED} type 
      POSVersionInfoEx = ^TOSVersionInfoEx; 
      TOSVersionInfoEx = packed record 
        dwOSVersionInfoSize: DWORD; 
        dwMajorVersion     : DWORD; 
        dwMinorVersion     : DWORD; 
        dwBuildNumber      : DWORD; 
        dwPlatformId       : DWORD; 
        szCSDVersion       : array [0..127] of AnsiChar; 
        wServicePackMajor  : Word; 
        wServicePackMinor  : Word; 
        wSuiteMask         : Word; 
        wProductType       : Byte; 
        wReserved          : Byte; 
      end; const 
      VER_SERVER_NT                       = $80000000; 
      {$EXTERNALSYM VER_SERVER_NT} 
      VER_WORKSTATION_NT                  = $40000000; 
      {$EXTERNALSYM VER_WORKSTATION_NT} 
      VER_SUITE_SMALLBUSINESS             = $00000001; 
      {$EXTERNALSYM VER_SUITE_SMALLBUSINESS} 
      VER_SUITE_ENTERPRISE                = $00000002; 
      {$EXTERNALSYM VER_SUITE_ENTERPRISE} 
      VER_SUITE_BACKOFFICE                = $00000004; 
      {$EXTERNALSYM VER_SUITE_BACKOFFICE} 
      VER_SUITE_COMMUNICATIONS            = $00000008; 
      {$EXTERNALSYM VER_SUITE_COMMUNICATIONS} 
      VER_SUITE_TERMINAL                  = $00000010; 
      {$EXTERNALSYM VER_SUITE_TERMINAL} 
      VER_SUITE_SMALLBUSINESS_RESTRICTED  = $00000020; 
      {$EXTERNALSYM VER_SUITE_SMALLBUSINESS_RESTRICTED} 
      VER_SUITE_EMBEDDEDNT                = $00000040; 
      {$EXTERNALSYM VER_SUITE_EMBEDDEDNT} 
      VER_SUITE_DATACENTER                = $00000080; 
      {$EXTERNALSYM VER_SUITE_DATACENTER} 
      VER_SUITE_SINGLEUSERTS              = $00000100; 
      {$EXTERNALSYM VER_SUITE_SINGLEUSERTS} 
      VER_SUITE_PERSONAL                  = $00000200; 
      {$EXTERNALSYM VER_SUITE_PERSONAL} 
      VER_SUITE_BLADE                     = $00000400; 
      {$EXTERNALSYM VER_SUITE_BLADE} 
      VER_SUITE_EMBEDDED_RESTRICTED       = $00000800; 
      {$EXTERNALSYM VER_SUITE_EMBEDDED_RESTRICTED} 
      VER_SUITE_SECURITY_APPLIANCE        = $00001000; 
      {$EXTERNALSYM VER_SUITE_SECURITY_APPLIANCE} const 
      VER_NT_WORKSTATION              = $0000001; 
      {$EXTERNALSYM VER_NT_WORKSTATION} 
      VER_NT_DOMAIN_CONTROLLER        = $0000002; 
      {$EXTERNALSYM VER_NT_DOMAIN_CONTROLLER} 
      VER_NT_SERVER                   = $0000003; 
      {$EXTERNALSYM VER_NT_SERVER} {$ENDIF}  // TOSVERSIONINFOEX_DEFINED 
    function GetOSVersionInfo(var Info: TOSVersionInfoEx): Boolean; 
    begin 
      FillChar(Info, SizeOf(TOSVersionInfoEx), 0); 
      Info.dwOSVersionInfoSize := SizeOf(TOSVersionInfoEx); 
      Result := GetVersionEx(TOSVersionInfo(Addr(Info)^)); 
      if (not Result) then 
      begin 
        FillChar(Info, SizeOf(TOSVersionInfoEx), 0); 
        Info.dwOSVersionInfoSize := SizeOf(TOSVersionInfoEx); 
        Result := GetVersionEx(TOSVersionInfo(Addr(Info)^)); 
        if (not Result) then 
          Info.dwOSVersionInfoSize := 0; 
      end; 
    end; function GetOSVersionText: string; 
    var 
      Info: TOSVersionInfoEx; 
      Key: HKEY; 
    begin 
      Result := ''; 
      if (not GetOSVersionInfo(Info)) then 
        Exit; 
      case Info.dwPlatformId of 
        { Win32s } 
        VER_PLATFORM_WIN32s: 
          Result := 'Microsoft Win32s'; 
        { Windows 9x } 
        VER_PLATFORM_WIN32_WINDOWS: 
          if (Info.dwMajorVersion = 4) and (Info.dwMinorVersion = 0) then 
          begin 
            Result := 'Microsoft Windows 95'; 
            if (Info.szCSDVersion[1] in ['B', 'C']) then 
              Result := Result +' OSR2'; 
          end 
          else if (Info.dwMajorVersion = 4) and (Info.dwMinorVersion = 10) then 
          begin 
            Result := 'Microsoft Windows 98'; 
            if (Info.szCSDVersion[1] = 'A') then 
              Result := Result + ' SE'; 
          end 
          else if (Info.dwMajorVersion = 4) and (Info.dwMinorVersion = 90) then 
            Result := 'Microsoft Windows Millennium Edition'; 
        { Windows NT } 
        VER_PLATFORM_WIN32_NT: 
          begin 
            { Version } 
            if (Info.dwMajorVersion = 5) and (Info.dwMinorVersion = 2) then 
              Result := 'Microsoft Windows Server 2003' 
            else if (Info.dwMajorVersion = 5) and (Info.dwMinorVersion = 1) then 
              Result := 'Microsoft Windows XP' 
            else if (Info.dwMajorVersion = 5) and (Info.dwMinorVersion = 0) then 
              Result := 'Microsoft Windows 2000' 
            else 
              Result := 'Microsoft Windows NT'; 
            { Extended } 
            if (Info.dwOSVersionInfoSize >= SizeOf(TOSVersionInfoEx)) then 
            begin 
              { ProductType } 
              if (Info.wProductType = VER_NT_WORKSTATION) then 
              begin 
                if (Info.dwMajorVersion = 4) then 
                  Result := Result + #10'Workstation 4.0' 
                else if(Info.wSuiteMask and VER_SUITE_PERSONAL <> 0) then 
                  Result := Result + #10'Home Edition' 
                else 
                  Result := Result + #10'Professional'; 
              end 
              else if (Info.wProductType = VER_NT_SERVER) then 
              begin 
                 if (Info.dwMajorVersion = 5) and (Info.dwMinorVersion = 2) then 
                 begin 
                   if (Info.wSuiteMask and VER_SUITE_DATACENTER <> 0) then 
                     Result := Result + #10'Datacenter Edition' 
                   else if (Info.wSuiteMask and VER_SUITE_ENTERPRISE <> 0) then 
                     Result := Result + #10'Enterprise Edition' 
                   else if (Info.wSuiteMask = VER_SUITE_BLADE) then 
                     Result := Result + #10'Web Edition' 
                   else 
                     Result := Result + #10'Standard Edition'; 
                 end 
                 else if (Info.dwMajorVersion = 5) and (Info.dwMinorVersion = 0) then 
                 begin 
                   if (Info.wSuiteMask and VER_SUITE_DATACENTER <> 0) then 
                      Result := Result + #10'Datacenter Server' 
                   else if (Info.wSuiteMask and VER_SUITE_ENTERPRISE <> 0) then 
                      Result := Result + #10'Advanced Server' 
                   else 
                      Result := Result + #10'Server'; 
                 end 
                 else 
                 begin 
                   Result := Result + #10'Server ' + 
                     IntToStr(Info.dwMajorVersion) + '.' + 
                     IntToStr(Info.dwMinorVersion); 
                   if (Info.wSuiteMask and VER_SUITE_ENTERPRISE <> 0) then 
                     Result := Result + ', Enterprise Edition'; 
                 end; 
              end; 
            end; 
            { CSDVersion } 
            if (Info.dwMajorVersion = 4) and 
              (StrIComp(Info.szCSDVersion, 'Service Pack 6') = 0) and 
              (RegOpenKeyEx(HKEY_LOCAL_MACHINE, 
                'SOFTWARE\Microsoft\Windows NT\CurrentVersion\Hotfix\Q246009', 0, 
                KEY_QUERY_VALUE, Key) = ERROR_SUCCESS) then 
            begin 
              Result := Result + #10'Service Pack 6a'; 
              RegCloseKey(Key); 
            end 
            else 
              Result := Result + #10 + StrPas(Info.szCSDVersion); 
            Result := Result + #10'(Build ' + 
              IntToStr(Info.dwBuildNumber and $FFFF) + ')'; 
          end; 
      end; 
    end; //////////////////////////////////////////////////////////////////////////////// procedure TForm1.Button1Click(Sender: TObject); 
    begin 
      ShowMessage(GetOSVersionText); 
    end; 
      

  12.   

    robot_8888 (编译人生) ,你的这个问题我可以用一个笨死的方法解出来~~1,首先明确在windows2000系统安装好以后,核心路径为:C:\Windows\
       而windows2000server系统,核心路径为:C:\WINNT
    2,接下来好办,在注册表中,\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\  中你会看到系统信息。
    3,在Delphi程序中,(条件一)读取ProductName首先确实是Microsoft Windows 2000
       然后,(条件二)读取PathName,若发现是C:\Windows\ 则判断是windows2000系统。
                           若发现是C:\WINNT 则是windows2000server系统。