直接调用,靠返回值判断版本号。这里只区分了XP系统跟其他系统两类。可以更改switch里面的return细化。
int Select_Version()
{
OSVERSIONINFO osvi;
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx((OSVERSIONINFO *)&osvi);
switch (osvi.dwMajorVersion)
{
case 5:
switch(osvi.dwMinorVersion)
{
case 0:
printf("WINDOWS 2000\n\n\n");
return 1;
break;
case 1:
printf("WINDOWS XP/x32\n\n\n");
return 1;
break;
case 2:
printf("WINDOWS XP/x64\n\n\n");
return 1;
break;
default:
printf("Select_Version FALSE:1.1 !!!\n\n\n");
break;
}
case 6:
switch(osvi.dwMinorVersion)
{
case 0:
printf("WINDOWS Vista\n\n\n");
return 2;
break;
case 1:
printf("WINDOWS 7\n\n\n");
return 2;
break;
case 2:
printf("WINDOWS 8\n\n\n");
return 3;
break;
case 3:
printf("WINDOWS 8.1\n\n\n");
return 3;
break;
default:
printf("Select_Version FALSE:1.2 !!!\n\n\n");
break;
}
default:
printf("Select_Version FALSE:1.0 !!!\n\n\n");
break;
}
return 0;
}
参考:http://msdn.microsoft.com/en-us/library/ms724451(VS.85).aspx
http://msdn.microsoft.com/en-us/library/ms724833(v=vs.85).aspx