Descobrindo o Sistema Operacional e a plataforma



#include "windows.h"
#include "winbase.h"
#include "stdio.h"

typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);
typedef BOOL (WINAPI *PGPI)(DWORD, DWORD, DWORD, DWORD, PDWORD);

int main()
{
     _OSVERSIONINFOEXA osvi;
     SYSTEM_INFO si;
     PGNSI pGNSI;
     PGPI pGPI;
     BOOL bOsVersionInfoEx;
     DWORD dwType;

     ZeroMemory(&si, sizeof(SYSTEM_INFO));
     osvi.dwOSVersionInfoSize = sizeof(osvi);

     if( !GetVersionEx ((OSVERSIONINFO *) &osvi) )
          return 1;

     pGNSI = (PGNSI) GetProcAddress( GetModuleHandle(TEXT("kernel32.dll")), "GetNativeSystemInfo");
     if(NULL != pGNSI)
          pGNSI(&si);
     else
          GetSystemInfo(&si);

     if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT && osvi.dwMajorVersion > 4 ) {

          if (osvi.dwMajorVersion == 6 ) {

               if(osvi.dwMinorVersion == 0 ) {
                    if( osvi.wProductType == VER_NT_WORKSTATION)
                         printf("Windows Vista ");
                    else
                         printf("Windows Server 2008");
               }

               if (osvi.dwMinorVersion == 1) {
                    if( osvi.wProductType == VER_NT_WORKSTATION )
                         printf("Windows 7");
                    else
                         printf("Windows Server 2008 R2");
               }

               pGPI = (PGPI) GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetProductInfo");
               pGPI( osvi.dwMajorVersion, osvi.dwMinorVersion, 0, 0, &dwType);

          }

          if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 ) {

               if ( osvi.wSuiteMask & VER_SUITE_STORAGE_SERVER )
                    printf( "Windows Storage Server 2003");
               else if( osvi.wProductType == VER_NT_WORKSTATION && si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
                    printf( "Windows XP Professional x64 Edition");
               else
                    printf("Windows Server 2003");
          }

          if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 ) {
               printf("Windows XP ");
               if( osvi.wSuiteMask & VER_SUITE_PERSONAL )
                    printf( "Home Edition");
               else
                    printf( "Professional");
          }

          if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 ) {
               printf("Windows 2000 ");

               if ( osvi.wProductType == VER_NT_WORKSTATION )
                    printf( "Professional");
               else {
                    if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
                         printf( "Datacenter Server");
                    else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
                         printf( "Advanced Server");
                    else
                         printf( "Server");
               }
          }

          if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64 )
               printf( " 64-bit" );
          else if (si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_INTEL )
               printf(" 32-bit");
     }

     return 0;
} 

Fonte: http://msdn.microsoft.com/en-us/library/windows/desktop/ms724429(v=vs.85).aspx




Comentários

Copyright © 2018 Anderson Bravo
www.andersonbravo.com.br
anderson@andersonbravo.com.br