GetOS en C++

  • 0 Respuestas
  • 2973 Vistas

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado Expermicid

  • *
  • Ex-Staff
  • *****
  • Mensajes: 458
  • Actividad:
    0%
  • Reputación 0
  • _-Expermicid-_
    • Ver Perfil

GetOS en C++

  • en: Enero 17, 2013, 01:50:48 pm
Hola a todos. En esta ocasion el code es para determinar el sistema operativo en el que se ejecuta.

Código: (c) You are not allowed to view links. Register or Login
#pragma comment(lib, "User32.lib")
#include <windows.h>
#include <iostream>

using namespace std;

void main(void) {

OSVERSIONINFOEX OSver;
    BOOL bOsVersionInfoEx;

    ZeroMemory(&OSver, sizeof(OSVERSIONINFOEX));

    OSver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
    bOsVersionInfoEx = GetVersionEx((OSVERSIONINFO*) &OSver);

    if(bOsVersionInfoEx == 0 )
cout << "Error" << endl;

switch(OSver.dwPlatformId) {
case VER_PLATFORM_WIN32s:
cout << "Windows " << OSver.dwMajorVersion << OSver.dwMinorVersion << endl;
break;
case VER_PLATFORM_WIN32_WINDOWS:
  if(OSver.dwMinorVersion==0)
cout << "Windows 95" << endl; 
else
if(OSver.dwMinorVersion==10) 
cout << "Windows 98" << endl;
        else
if(OSver.dwMinorVersion==90) 
cout << "Windows Me" << endl;
break;
case VER_PLATFORM_WIN32_NT:
  if(OSver.dwMajorVersion==5 && OSver.dwMinorVersion==0)
cout << "Windows 2000" << OSver.szCSDVersion << endl;
else
if(OSver.dwMajorVersion==5 && OSver.dwMinorVersion==1)
cout << "Windows XP " << OSver.szCSDVersion << endl;
else
if(OSver.dwMajorVersion==5 && OSver.dwMinorVersion==2)
if (OSver.wProductType==VER_NT_WORKSTATION)
cout << "Windows XP Profesional x64" << endl;
else
cout << "Windows Server 2003" << endl;
else
if(OSver.dwMajorVersion==6 && OSver.dwMinorVersion==0)
if (OSver.wProductType==VER_NT_WORKSTATION)
cout << "Windows Vista" << endl;
else
cout << "Windows Server 2008" << endl;
    else
if(OSver.dwMajorVersion==6 && OSver.dwMinorVersion==1)
if (OSver.wProductType==VER_NT_WORKSTATION)
cout << "Windows 7" << endl;
else
cout << "Windows Server 2008 R2" << endl;
else
if(OSver.dwMajorVersion==6 && OSver.dwMinorVersion==2)
if (OSver.wProductType==VER_NT_WORKSTATION)
cout << "Windows 8" << endl;
else
cout << "Windows Server 2012" << endl;
else
if(OSver.dwMajorVersion<=4)
cout << "Windows NT" << endl;
else
cout << "Windows " << OSver.dwMajorVersion << OSver.dwMinorVersion << endl;
break;
}
getchar();
}

Gracias a la api GetVersionEx y con la estructura OSVERSIONINFOEX podemos obtener mucha informacion del sistema operativo.

Un ejemplo:



Saludos