Chào mừng đến với Diễn đàn lập trình - Cộng đồng lập trình.
Kết quả 1 đến 2 của 2
  1. #1
    Ngày tham gia
    Sep 2015
    Bài viết
    0

    Detect Windows Vista/7 bằng sử dụng GetVersionEx API

    Func GetVersionEx sẽ điền đầy cấu trúc OSVERSIONINFO hoặc OSVERSIONINFOEX . Khi đó, để lấy thông tin về các phiên bản Windows ta sử dụng các trường của cấu trúc này.

    Mã:
    #include <windows.h>#include <tchar.h>#include <stdio.h>#include <strsafe.h> #pragma comment(lib, "User32.lib") #define BUFSIZE 256 typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);typedef BOOL (WINAPI *PGPI)(DWORD, DWORD, DWORD, DWORD, PDWORD); BOOL GetOSDisplayString( LPTSTR pszOS){   OSVERSIONINFOEX osvi;   SYSTEM_INFO si;   PGNSI pGNSI;   PGPI pGPI;   BOOL bOsVersionInfoEx;   DWORD dwType;    ZeroMemory(&si, sizeof(SYSTEM_INFO));   ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);    if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) )      return 1;    // Call GetNativeSystemInfo if supported or GetSystemInfo otherwise.    pGNSI = (PGNSI) GetProcAddress(      GetModuleHandle(TEXT("kernel32.dll")),       "GetNativeSystemInfo");   if(NULL != pGNSI)      pGNSI(&si);   else GetSystemInfo(&si);    if ( VER_PLATFORM_WIN32_NT==osvi.dwPlatformId &&         osvi.dwMajorVersion > 4 )   {      StringCchCopy(pszOS, BUFSIZE, TEXT("Microsoft "));       // Test for the specific product.       if ( osvi.dwMajorVersion == 6 )      {         if( osvi.dwMinorVersion == 0 )         {            if( osvi.wProductType == VER_NT_WORKSTATION )                StringCchCat(pszOS, BUFSIZE, TEXT("Windows Vista "));            else StringCchCat(pszOS, BUFSIZE, TEXT("Windows Server 2008 " ));         }          if ( osvi.dwMinorVersion == 1 )         {            if( osvi.wProductType == VER_NT_WORKSTATION )                StringCchCat(pszOS, BUFSIZE, TEXT("Windows 7 "));            else StringCchCat(pszOS, BUFSIZE, TEXT("Windows Server 2008 R2 " ));         }                  pGPI = (PGPI) GetProcAddress(            GetModuleHandle(TEXT("kernel32.dll")),             "GetProductInfo");          pGPI( osvi.dwMajorVersion, osvi.dwMinorVersion, 0, 0, &dwType);          switch( dwType )         {            case PRODUCT_ULTIMATE:               StringCchCat(pszOS, BUFSIZE, TEXT("Ultimate Edition" ));               break;            case PRODUCT_HOME_PREMIUM:               StringCchCat(pszOS, BUFSIZE, TEXT("Home Premium Edition" ));               break;            case PRODUCT_HOME_BASIC:               StringCchCat(pszOS, BUFSIZE, TEXT("Home Basic Edition" ));               break;            case PRODUCT_ENTERPRISE:               StringCchCat(pszOS, BUFSIZE, TEXT("Enterprise Edition" ));               break;            case PRODUCT_BUSINESS:               StringCchCat(pszOS, BUFSIZE, TEXT("Business Edition" ));               break;            case PRODUCT_STARTER:               StringCchCat(pszOS, BUFSIZE, TEXT("Starter Edition" ));               break;            case PRODUCT_CLUSTER_SERVER:               StringCchCat(pszOS, BUFSIZE, TEXT("Cluster Server Edition" ));               break;            case PRODUCT_DATACENTER_SERVER:               StringCchCat(pszOS, BUFSIZE, TEXT("Datacenter Edition" ));               break;            case PRODUCT_DATACENTER_SERVER_CORE:               StringCchCat(pszOS, BUFSIZE, TEXT("Datacenter Edition (core installation)" ));               break;            case PRODUCT_ENTERPRISE_SERVER:               StringCchCat(pszOS, BUFSIZE, TEXT("Enterprise Edition" ));               break;            case PRODUCT_ENTERPRISE_SERVER_CORE:               StringCchCat(pszOS, BUFSIZE, TEXT("Enterprise Edition (core installation)" ));               break;            case PRODUCT_ENTERPRISE_SERVER_IA64:               StringCchCat(pszOS, BUFSIZE, TEXT("Enterprise Edition for Itanium-based Systems" ));               break;            case PRODUCT_SMALLBUSINESS_SERVER:               StringCchCat(pszOS, BUFSIZE, TEXT("Small Business Server" ));               break;            case PRODUCT_SMALLBUSINESS_SERVER_PREMIUM:               StringCchCat(pszOS, BUFSIZE, TEXT("Small Business Server Premium Edition" ));               break;            case PRODUCT_STANDARD_SERVER:               StringCchCat(pszOS, BUFSIZE, TEXT("Standard Edition" ));               break;            case PRODUCT_STANDARD_SERVER_CORE:               StringCchCat(pszOS, BUFSIZE, TEXT("Standard Edition (core installation)" ));               break;            case PRODUCT_WEB_SERVER:               StringCchCat(pszOS, BUFSIZE, TEXT("Web Server Edition" ));               break;         }      }       if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 )      {         if( GetSystemMetrics(SM_SERVERR2) )            StringCchCat(pszOS, BUFSIZE, TEXT( "Windows Server 2003 R2, "));         else if ( osvi.wSuiteMask==VER_SUITE_STORAGE_SERVER )            StringCchCat(pszOS, BUFSIZE, TEXT( "Windows Storage Server 2003"));         else if ( osvi.wSuiteMask==VER_SUITE_WH_SERVER )            StringCchCat(pszOS, BUFSIZE, TEXT( "Windows Home Server"));         else if( osvi.wProductType == VER_NT_WORKSTATION &&                  si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64)         {            StringCchCat(pszOS, BUFSIZE, TEXT( "Windows XP Professional x64 Edition"));         }         else StringCchCat(pszOS, BUFSIZE, TEXT("Windows Server 2003, "));          // Test for the server type.         if ( osvi.wProductType != VER_NT_WORKSTATION )         {            if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_IA64 )            {                if( osvi.wSuiteMask & VER_SUITE_DATACENTER )                   StringCchCat(pszOS, BUFSIZE, TEXT( "Datacenter Edition for Itanium-based Systems" ));                else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )                   StringCchCat(pszOS, BUFSIZE, TEXT( "Enterprise Edition for Itanium-based Systems" ));            }             else if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64 )            {                if( osvi.wSuiteMask & VER_SUITE_DATACENTER )                   StringCchCat(pszOS, BUFSIZE, TEXT( "Datacenter x64 Edition" ));                else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )                   StringCchCat(pszOS, BUFSIZE, TEXT( "Enterprise x64 Edition" ));                else StringCchCat(pszOS, BUFSIZE, TEXT( "Standard x64 Edition" ));            }             else            {                if ( osvi.wSuiteMask & VER_SUITE_COMPUTE_SERVER )                   StringCchCat(pszOS, BUFSIZE, TEXT( "Compute Cluster Edition" ));                else if( osvi.wSuiteMask & VER_SUITE_DATACENTER )                   StringCchCat(pszOS, BUFSIZE, TEXT( "Datacenter Edition" ));                else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )                   StringCchCat(pszOS, BUFSIZE, TEXT( "Enterprise Edition" ));                else if ( osvi.wSuiteMask & VER_SUITE_BLADE )                   StringCchCat(pszOS, BUFSIZE, TEXT( "Web Edition" ));                else StringCchCat(pszOS, BUFSIZE, TEXT( "Standard Edition" ));            }         }      }       if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 )      {         StringCchCat(pszOS, BUFSIZE, TEXT("Windows XP "));         if( osvi.wSuiteMask & VER_SUITE_PERSONAL )            StringCchCat(pszOS, BUFSIZE, TEXT( "Home Edition" ));         else StringCchCat(pszOS, BUFSIZE, TEXT( "Professional" ));      }       if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 )      {         StringCchCat(pszOS, BUFSIZE, TEXT("Windows 2000 "));          if ( osvi.wProductType == VER_NT_WORKSTATION )         {            StringCchCat(pszOS, BUFSIZE, TEXT( "Professional" ));         }         else          {            if( osvi.wSuiteMask & VER_SUITE_DATACENTER )               StringCchCat(pszOS, BUFSIZE, TEXT( "Datacenter Server" ));            else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )               StringCchCat(pszOS, BUFSIZE, TEXT( "Advanced Server" ));            else StringCchCat(pszOS, BUFSIZE, TEXT( "Server" ));         }      }        // Include service pack (if any) and build number.       if( _tcslen(osvi.szCSDVersion) > 0 )      {          StringCchCat(pszOS, BUFSIZE, TEXT(" ") );          StringCchCat(pszOS, BUFSIZE, osvi.szCSDVersion);      }       TCHAR buf[80];       StringCchPrintf( buf, 80, TEXT(" (build %d)"), osvi.dwBuildNumber);      StringCchCat(pszOS, BUFSIZE, buf);       if ( osvi.dwMajorVersion >= 6 )      {         if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64 )            StringCchCat(pszOS, BUFSIZE, TEXT( ", 64-bit" ));         else if (si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_INTEL )            StringCchCat(pszOS, BUFSIZE, TEXT(", 32-bit"));      }            return TRUE;    }    else   {        printf( "This sample does not support this version of Windows.
    ");      return FALSE;   }} int __cdecl _tmain(){    TCHAR szOS[BUFSIZE];     if( GetOSDisplayString( szOS ) )        _tprintf( TEXT("
    %s
    "), szOS );}

  2. #2
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    Mã:
    typedef OSVERSIONINFObeginLONG dwOSVersionInfoSize;LONG dwMajorVersion;LONG dwMinorVersion;LONG dwBuildNumber;LONG dwPlatformId; //20STRING szCSDVersion[ 128 ]; //148end; typedef OSVERSIONINFOEXbeginLONG dwOSVersionInfoSize;LONG dwMajorVersion;LONG dwMinorVersion;LONG dwBuildNumber;LONG dwPlatformId; //20STRING szCSDVersion[ 128 ]; //148NUMBER wServicePackMajor;NUMBER wServicePackMinor;NUMBER wSuiteMask;NUMBER wProductType;NUMBER wReserved; //156end; //prototype BOOL Kernel32.GetVersionEx(OSVERSIONINFO POINTER);prototype BOOL Kernel32.GetVersionEx(OSVERSIONINFOEX POINTER); function BOOL DetermineSystemVersion(hMSI)OSVERSIONINFOEX osviex;OSVERSIONINFO osvi;BOOL bOsVersionInfoEx;LONG hKey;STRING szProductType[80];LONG dwBufLen;begin// Try calling GetVersionEx using the OSVERSIONINFOEX structure.//// If that fails, try using the OSVERSIONINFO structure. osviex.dwOSVersionInfoSize = 156; bOsVersionInfoEx = GetVersionEx(&osviex); if (!bOsVersionInfoEx) thenSprintfBox(WARNING,"","GerVersionEx(OSVERSIONINFOEX) failed: %d",GetLastError());// If OSVERSIONINFOEX doesn't work, try OSVERSIONINFO. osvi.dwOSVersionInfoSize = 148;//SprintfBox(INFORMATION,"","%d",osvi.dwOSVersionInfoSize); bOsVersionInfoEx = GetVersionEx(&osvi); if (!bOsVersionInfoEx) thenreturn FALSE;elseswitch (osvi.dwPlatformId)case VER_PLATFORM_WIN32_NT:     // Test for the product.     if ( osvi.dwMajorVersion <= 4 ) then        MessageBox("Microsoft Windows NT ",INFORMATION);    endif;     if ( osvi.dwMajorVersion = 5 && osvi.dwMinorVersion = 0 ) then        MessageBox("Microsoft Windows 2000 ",INFORMATION);    endif;     if ( osvi.dwMajorVersion = 5 && osvi.dwMinorVersion = 1 ) then        MessageBox("Microsoft Windows XP ",INFORMATION);    endif;     // Test for product type.     RegOpenKeyEx( HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\ProductOptions", 0, KEY_QUERY_VALUE, &hKey );    RegQueryValueEx( hKey, "ProductType", NULL, NULL, szProductType, &dwBufLen);    RegCloseKey( hKey );     //MessageBox(szProductType,INFORMATION);     if ( StrCompare("WINNT", szProductType) = 0 ) then        MessageBox( "Professional " ,INFORMATION);    endif;     if ( StrCompare( "LANMANNT", szProductType) = 0 ) then        MessageBox( "Server " ,INFORMATION);    endif;     if ( StrCompare( "SERVERNT", szProductType) = 0 ) then        MessageBox( "Advanced Server " ,INFORMATION);    endif;     // Display version, service pack (if any), and build number.     if ( osvi.dwMajorVersion <= 4 ) then        SprintfBox(INFORMATION,"","version %d.%d %s (Build %d)
    ", osvi.dwMajorVersion, osvi.dwMinorVersion, osvi.szCSDVersion, osvi.dwBuildNumber & 0xFFFF);    else        SprintfBox (INFORMATION,"","%s (Build %d)
    ", osvi.szCSDVersion, osvi.dwBuildNumber & 0xFFFF);    endif; case VER_PLATFORM_WIN32_WINDOWS:     if (osvi.dwMajorVersion = 4 && osvi.dwMinorVersion = 0) then        MessageBox ("Microsoft Windows 95 ",INFORMATION);    if ( osvi.szCSDVersion[1] = 'C' || osvi.szCSDVersion[1] = 'B' ) then        MessageBox("OSR2 " ,INFORMATION);    endif;    endif;     if (osvi.dwMajorVersion = 4 && osvi.dwMinorVersion = 10) then        MessageBox ("Microsoft Windows 98 ",INFORMATION);    if ( osvi.szCSDVersion[1] = 'A' ) then        MessageBox("SE " ,INFORMATION);    endif;    endif;     if (osvi.dwMajorVersion = 4 && osvi.dwMinorVersion = 90) then        MessageBox ("Microsoft Windows Me ",INFORMATION);    endif; case VER_PLATFORM_WIN32s:    MessageBox ("Microsoft Win32s ",INFORMATION);    endswitch;    endif;    else        SprintfBox(WARNING,"","GetVersionEx(OSVERSIONINFOEX) succeeded.");    SprintfBox(INFORMATION,"Version Information","MajorVersion: %d
    MinorVersion: %d
    BuildNumber: %d
    PlatformId: %d
    CSDVersion: %s
    ServicePackMajor: %d
    ServicePackMinor: %d
    SuiteMask: %d
    ProductType: %d
    Reserved: %d",osviex.dwMajorVersion, osviex.dwMinorVersion, osviex.dwBuildNumber, osviex.dwPlatformId, osviex.szCSDVersion, osviex.wServicePackMajor, osviex.wServicePackMinor, osviex.wSuiteMask, osviex.wProductType, osviex.wReserved);    switch (osviex.dwPlatformId)case VER_PLATFORM_WIN32_NT:     // Test for the product.     if ( osviex.dwMajorVersion <= 4 ) then        MessageBox("Microsoft Windows NT ",INFORMATION);    endif;     if ( osviex.dwMajorVersion = 5 && osviex.dwMinorVersion = 0 ) then        MessageBox ("Microsoft Windows 2000 ",INFORMATION);    endif;     if ( osviex.dwMajorVersion = 5 && osviex.dwMinorVersion = 1 ) then        MessageBox ("Microsoft Windows XP ",INFORMATION);    endif;     // Test for product type.     if ( bOsVersionInfoEx ) then        if ( osviex.wProductType = VER_NT_WORKSTATION ) then            if ( osviex.wSuiteMask & VER_SUITE_PERSONAL ) then                MessageBox ( "Personal " ,INFORMATION);            else                MessageBox ( "Professional " ,INFORMATION);    endif;    elseif ( osviex.wProductType = VER_NT_SERVER ) then        if ( osviex.wSuiteMask & VER_SUITE_DATACENTER ) then            MessageBox ( "DataCenter Server " ,INFORMATION);    elseif ( osviex.wSuiteMask & VER_SUITE_ENTERPRISE ) then        MessageBox ( "Advanced Server " ,INFORMATION);        else            MessageBox ( "Server " ,INFORMATION);    endif;    endif;        else            RegOpenKeyEx( HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\ProductOptions", 0, KEY_QUERY_VALUE, &hKey );    RegQueryValueEx( hKey, "ProductType", NULL, NULL, szProductType, &dwBufLen);    RegCloseKey( hKey );     //MessageBox(szProductType,INFORMATION);     if ( StrCompare( "WINNT", szProductType) = 0 ) then        MessageBox( "Professional " ,INFORMATION);    endif;     if ( StrCompare( "LANMANNT", szProductType) = 0 ) then        MessageBox( "Server " ,INFORMATION);    endif;     if ( StrCompare( "SERVERNT", szProductType) = 0 ) then        MessageBox( "Advanced Server " ,INFORMATION);    endif;    endif;     // Display version, service pack (if any), and build number.     if ( osviex.dwMajorVersion <= 4 ) then        SprintfBox (INFORMATION,"","version %d.%d %s (Build %d)
    ", osviex.dwMajorVersion, osviex.dwMinorVersion, osviex.szCSDVersion, osviex.dwBuildNumber & 0xFFFF);    else        SprintfBox (INFORMATION,"","%s (Build %d)
    ", osviex.szCSDVersion, osviex.dwBuildNumber & 0xFFFF);    endif; case VER_PLATFORM_WIN32_WINDOWS:     if (osviex.dwMajorVersion = 4 && osviex.dwMinorVersion = 0) then        MessageBox ("Microsoft Windows 95 ",INFORMATION);    if ( osviex.szCSDVersion[1] = 'C' || osviex.szCSDVersion[1] = 'B' ) then        MessageBox("OSR2 " ,INFORMATION);    endif;    endif;     if (osviex.dwMajorVersion = 4 && osviex.dwMinorVersion = 10) then        MessageBox ("Microsoft Windows 98 ",INFORMATION);    if ( osviex.szCSDVersion[1] = 'A' ) then        MessageBox("SE " ,INFORMATION);    endif;    endif;     if (osviex.dwMajorVersion = 4 && osviex.dwMinorVersion = 90) then        MessageBox ("Microsoft Windows Me ",INFORMATION);    endif; case VER_PLATFORM_WIN32s:    MessageBox ("Microsoft Win32s ",INFORMATION);    endswitch;    endif;     return TRUE;    end;     I've tested this code on Windows 2000 Server (SP2) and Windows XP Home, and GetVersionEx(OSVERSIONINFOEX) succeeds on both OSs.        However, the wSuiteMask and wProductType properties of the OSVERSIONINFOEX structure are always 0. Furthermore, the wServicePackMinor property doesn't seem to be correct. On the Windows 2000 Server (SP2) machine, it equivalates to 503513088.        On the Windows XP Home machine, it equivalates to 66304.         I know the old winbase.h header file specifies the OSVERSIONINFOEX structure like this:    typedef struct _OSVERSIONINFOEXA {        DWORD dwOSVersionInfoSize;        DWORD dwMajorVersion;        DWORD dwMinorVersion;        DWORD dwBuildNumber;        DWORD dwPlatformId;        CHAR szCSDVersion[ 128 ];        WORD wServicePackMajor;        WORD wServicePackMinor;        WORD wReserved[2];    } OSVERSIONINFOEXA, *POSVERSIONINFOEXA, *LPOSVERSIONINFOEXA;     Whereas the latest winnt.h header file specifies the OSVERSIONINFOEX structure like this:    typedef struct _OSVERSIONINFOEXA {        DWORD dwOSVersionInfoSize;        DWORD dwMajorVersion;        DWORD dwMinorVersion;        DWORD dwBuildNumber;        DWORD dwPlatformId;        CHAR szCSDVersion[ 128 ];        WORD wServicePackMajor;        WORD wServicePackMinor;        WORD wSuiteMask;        BYTE wProductType;        BYTE wReserved;    } OSVERSIONINFOEXA, *POSVERSIONINFOEXA, *LPOSVERSIONINFOEXA;
    Mã:
    void OnDetect() {    OSVERSIONINFO OSversion;    OSversion.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);    ::GetVersionEx(&OSversion);    switch(OSversion.dwPlatformId)    {    case VER_PLATFORM_WIN32s:         m_sStr.Format("Windows %d.%d",OSversion.dwMajorVersion,            OSversion.dwMinorVersion);        break;    case VER_PLATFORM_WIN32_WINDOWS:        if(OSversion.dwMinorVersion==0)            m_sStr="Windows    95";          else            if(OSversion.dwMinorVersion==10)                  m_sStr="Windows    98";            else                if(OSversion.dwMinorVersion==90)                      m_sStr="Windows    Me";            break;            case VER_PLATFORM_WIN32_NT:        if(OSversion.dwMajorVersion==5 && OSversion.dwMinorVersion==0)            m_sStr.Format("Windows 2000 With %s",OSversion.szCSDVersion);        else                                                    if(OSversion.dwMajorVersion==5 && OSversion.dwMinorVersion==1)                m_sStr.Format("Windows XP %s",OSversion.szCSDVersion);            else                    if(OSversion.dwMajorVersion<=4)                           m_sStr.Format("Windows NT %d.%d with %s",OSversion.dwMajorVersion,                    OSversion.dwMinorVersion,OSversion.szCSDVersion);                else                        // for unknown windowsewest windows version                          m_sStr.Format("Windows %d.%d ",OSversion.dwMajorVersion,                    OSversion.dwMinorVersion);    }}
    Mã:
    #include <windows.h>#include <tchar.h>#include <stdio.h>#include <strsafe.h>#pragma comment(lib, "User32.lib")#define BUFSIZE 256typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);BOOL GetOSDisplayString( LPTSTR pszOS){    OSVERSIONINFOEX osvi;    SYSTEM_INFO si;    PGNSI pGNSI;    BOOL bOsVersionInfoEx;    ZeroMemory(&si, sizeof(SYSTEM_INFO));    ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);    if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) )        return 1;    pGNSI = (PGNSI) GetProcAddress(        GetModuleHandle(TEXT("kernel32.dll")),        "GetNativeSystemInfo");    if(NULL != pGNSI)        pGNSI(&si);    else GetSystemInfo(&si);    if ( VER_PLATFORM_WIN32_NT==osvi.dwPlatformId &&        osvi.dwMajorVersion > 4 )    {        StringCchCopy(pszOS, BUFSIZE, TEXT("Microsoft "));        // Test for the specific product.        if ( osvi.dwMajorVersion == 6 )        {            if( osvi.dwMinorVersion == 0 )            {                if( osvi.wProductType == VER_NT_WORKSTATION )                    StringCchCat(pszOS, BUFSIZE, TEXT("Windows Vista "));                else StringCchCat(pszOS, BUFSIZE, TEXT("Windows Server 2008 " ));            }            if ( osvi.dwMinorVersion == 1 )            {                if( osvi.wProductType == VER_NT_WORKSTATION )                    StringCchCat(pszOS, BUFSIZE, TEXT("Windows 7 "));                else StringCchCat(pszOS, BUFSIZE, TEXT("Windows Server 2008 R2 " ));            }        }        if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 )        {            if( GetSystemMetrics(SM_SERVERR2) )                StringCchCat(pszOS, BUFSIZE, TEXT( "Windows Server 2003 R2, "));            else if ( osvi.wSuiteMask==VER_SUITE_STORAGE_SERVER )                StringCchCat(pszOS, BUFSIZE, TEXT( "Windows Storage Server 2003"));            else if( osvi.wProductType == VER_NT_WORKSTATION &&                si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64)            {                StringCchCat(pszOS, BUFSIZE, TEXT( "Windows XP Professional x64 Edition"));            }            else StringCchCat(pszOS, BUFSIZE, TEXT("Windows Server 2003, "));        }        if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 )        {            StringCchCat(pszOS, BUFSIZE, TEXT("Windows XP "));        }        if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 )        {            StringCchCat(pszOS, BUFSIZE, TEXT("Windows 2000 "));        }    }    return TRUE;}int main(){    TCHAR szOS[BUFSIZE];    if( GetOSDisplayString( szOS ) )        _tprintf( TEXT("
    %s
    "), szOS );    return 0;}
    Mã:
    #include <Windows.h>#include<stdio.h>void OnDetect() {    OSVERSIONINFO OSversion;    OSversion.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);    ::GetVersionEx(&OSversion);    switch(OSversion.dwPlatformId)    {    case VER_PLATFORM_WIN32s:         printf("Windows %d.%d",OSversion.dwMajorVersion,OSversion.dwMinorVersion);        break;    case VER_PLATFORM_WIN32_WINDOWS:        if(OSversion.dwMinorVersion==0)            printf("Windows    95");          else            if(OSversion.dwMinorVersion==10)                  printf("Windows    98");            else                if(OSversion.dwMinorVersion==90)                      printf("Windows    Me");            break;            case VER_PLATFORM_WIN32_NT:        if(OSversion.dwMajorVersion==5 && OSversion.dwMinorVersion==0)            printf("Windows 2000 With %s",OSversion.szCSDVersion);        else                                                    if(OSversion.dwMajorVersion==5 && OSversion.dwMinorVersion==1)                printf("Windows XP %s",OSversion.szCSDVersion);            else                    if(OSversion.dwMajorVersion<=4)                           printf("Windows NT %d.%d with %s",OSversion.dwMajorVersion,                    OSversion.dwMinorVersion,OSversion.szCSDVersion);                else                        // for unknown windowsewest windows version                          printf("Windows %d.%d ",OSversion.dwMajorVersion,                    OSversion.dwMinorVersion);    }}int main(){    OnDetect();    return 0;}

 

 

Quyền viết bài

  • Bạn Không thể gửi Chủ đề mới
  • Bạn Không thể Gửi trả lời
  • Bạn Không thể Gửi file đính kèm
  • Bạn Không thể Sửa bài viết của mình
  •