Sáb Mar 23, 2013 8:20 pm
Hola a todos. En esta ocasion el code es para determinar el sistema operativo en el que se ejecuta.
Gracias a la api GetVersionEx y con la estructura OSVERSIONINFOEX podemos obtener mucha informacion del sistema operativo.
Un ejemplo:
Saludos
- Código:
#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