分享
 
 
 

如何获得Windows 操作系统的版本

王朝vc·作者佚名  2006-01-10
窄屏简体版  字體: |||超大  

流水- 代码来自: MSDN

#include <windows.h>

#include <stdio.h>

#define BUFSIZE 80

BOOL GetOSVer(char *szOSName);

int main()

{

char szname[MAX_PATH];

memset(szname,0,MAX_PATH);

BOOL bRet = GetOSVer(szname);

printf("Your Os version is %s\n ",szname);

return 0;

}

BOOL GetOSVer(char *szname)

{

OSVERSIONINFOEX osvi;

BOOL bOsVersionInfoEx;

// Try calling GetVersionEx using the OSVERSIONINFOEX structure.

// If that fails, try using the OSVERSIONINFO structure.

ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));

osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);

if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) )

{

osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);

if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) )

return FALSE;

}

switch (osvi.dwPlatformId)

{

// Test for the Windows NT product family.

case VER_PLATFORM_WIN32_NT:

// Test for the specific product family.

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

strcpy(szname,"Microsoft Windows Server 2003 family, ");

if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 )

strcpy(szname,"Microsoft Windows XP ");

if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 )

strcpy(szname,"Microsoft Windows 2000 ");

if ( osvi.dwMajorVersion <= 4 )

strcpy(szname,"Microsoft Windows NT ");

// Test for specific product on Windows NT 4.0 SP6 and later.

if( bOsVersionInfoEx )

{

// Test for the workstation type.

if ( osvi.wProductType == VER_NT_WORKSTATION )

{

if( osvi.dwMajorVersion == 4 )

strcat(szname, "Workstation 4.0 " );

else if( osvi.wSuiteMask & VER_SUITE_PERSONAL )

strcat(szname, "Home Edition " );

else

strcat(szname, "Professional " );

}

// Test for the server type.

else if ( osvi.wProductType == VER_NT_SERVER )

{

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

{

if( osvi.wSuiteMask & VER_SUITE_DATACENTER )

strcat(szname, "Datacenter Edition " );

else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )

strcat(szname, "Enterprise Edition " );

else if ( osvi.wSuiteMask == VER_SUITE_BLADE )

strcat(szname, "Web Edition " );

else

strcat(szname, "Standard Edition " );

}

else if( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 )

{

if( osvi.wSuiteMask & VER_SUITE_DATACENTER )

strcat(szname, "Datacenter Server " );

else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )

strcat(szname, "Advanced Server " );

else

strcat(szname, "Server " );

}

else // Windows NT 4.0

{

if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )

strcat(szname,"Server 4.0, Enterprise Edition " );

else

strcat(szname, "Server 4.0 " );

}

}

}

else // Test for specific product on Windows NT 4.0 SP5 and earlier

{

HKEY hKey;

char szProductType[BUFSIZE];

DWORD dwBufLen=BUFSIZE;

LONG lRet;

lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE,

"SYSTEM\\CurrentControlSet\\Control\\ProductOptions",

0, KEY_QUERY_VALUE, &hKey );

if( lRet != ERROR_SUCCESS )

return FALSE;

lRet = RegQueryValueEx( hKey, "ProductType", NULL, NULL,

(LPBYTE) szProductType, &dwBufLen);

if( (lRet != ERROR_SUCCESS) || (dwBufLen > BUFSIZE) )

return FALSE;

RegCloseKey( hKey );

if ( lstrcmpi( "WINNT", szProductType) == 0 )

strcat(szname, "Workstation " );

if ( lstrcmpi( "LANMANNT", szProductType) == 0 )

strcat(szname, "Server " );

if ( lstrcmpi( "SERVERNT", szProductType) == 0 )

strcat(szname,"Advanced Server " );

printf( "%d.%d ", osvi.dwMajorVersion, osvi.dwMinorVersion );

}

// Display service pack (if any) and build number.

if( osvi.dwMajorVersion == 4 &&

lstrcmpi( osvi.szCSDVersion, "Service Pack 6" ) == 0 )

{

HKEY hKey;

LONG lRet;

// Test for SP6 versus SP6a.

lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE,

"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Hotfix\\Q246009",

0, KEY_QUERY_VALUE, &hKey );

if( lRet == ERROR_SUCCESS )

printf( "Service Pack 6a (Build %d)\n", osvi.dwBuildNumber & 0xFFFF );

else // Windows NT 4.0 prior to SP6a

{

printf( "%s (Build %d)\n",

osvi.szCSDVersion,

osvi.dwBuildNumber & 0xFFFF);

}

RegCloseKey( hKey );

}

else // Windows NT 3.51 and earlier or Windows 2000 and later

{

printf( "%s (Build %d)\n",

osvi.szCSDVersion,

osvi.dwBuildNumber & 0xFFFF);

}

break;

// Test for the Windows 95 product family.

case VER_PLATFORM_WIN32_WINDOWS:

if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0)

{

strcpy(szname,"Microsoft Windows 95 ");

if ( osvi.szCSDVersion[1] == 'C' || osvi.szCSDVersion[1] == 'B' )

strcat(szname,"OSR2 " );

}

if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10)

{

strcpy(szname,"Microsoft Windows 98 ");

if ( osvi.szCSDVersion[1] == 'A' )

strcat(szname,"SE " );

}

if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90)

{

strcpy(szname,"Microsoft Windows Millennium Edition\n");

}

break;

case VER_PLATFORM_WIN32s:

printf ("Microsoft Win32s\n");

break;

}

// getchar();

return TRUE;

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有