用c++写一段判断windows系统版本的程序
时间: 2023-09-08 14:05:12 浏览: 184
### 回答1:
#include <stdio.h>
int main(){
char version[10];
printf("请输入您的Windows系统版本号:");
scanf("%s",version);
if(strcmp(version,"Windows 10")==0){
printf("您的Windows系统版本为Windows 10");
}
else if (strcmp(version,"Windows 8")==0){
printf("您的Windows系统版本为Windows 8");
}
else if (strcmp(version,"Windows 7")==0){
printf("您的Windows系统版本为Windows 7");
}
else{
printf("抱歉,您的Windows系统版本暂时无法识别");
}
return 0;
}
### 回答2:
以下是用C语言编写的判断Windows系统版本的程序:
```c
#include <stdio.h>
#include <Windows.h>
int main()
{
// 获取操作系统版本信息
OSVERSIONINFO osInfo;
ZeroMemory(&osInfo, sizeof(OSVERSIONINFO));
osInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&osInfo);
// 判断操作系统版本
if (osInfo.dwMajorVersion == 10 && osInfo.dwMinorVersion == 0)
{
if (osInfo.wProductType == VER_NT_WORKSTATION)
printf("Windows 10");
else
printf("Windows Server 2016");
}
else if (osInfo.dwMajorVersion == 6 && osInfo.dwMinorVersion == 3)
{
if (osInfo.wProductType == VER_NT_WORKSTATION)
printf("Windows 8.1");
else
printf("Windows Server 2012 R2");
}
else if (osInfo.dwMajorVersion == 6 && osInfo.dwMinorVersion == 2)
{
if (osInfo.wProductType == VER_NT_WORKSTATION)
printf("Windows 8");
else
printf("Windows Server 2012");
}
else if (osInfo.dwMajorVersion == 6 && osInfo.dwMinorVersion == 1)
{
if (osInfo.wProductType == VER_NT_WORKSTATION)
printf("Windows 7");
else
printf("Windows Server 2008 R2");
}
else if (osInfo.dwMajorVersion == 6 && osInfo.dwMinorVersion == 0)
{
if (osInfo.wProductType == VER_NT_WORKSTATION)
printf("Windows Vista");
else
printf("Windows Server 2008");
}
else if (osInfo.dwMajorVersion == 5 && osInfo.dwMinorVersion == 2)
{
if (GetSystemMetrics(SM_SERVERR2))
printf("Windows Server 2003 R2");
else if (osInfo.wSuiteMask & VER_SUITE_WH_SERVER)
printf("Windows Home Server");
else if (osInfo.wProductType == VER_NT_WORKSTATION && GetSystemMetrics(SM_TABLETPC))
printf("Windows XP Tablet PC Edition");
else
printf("Windows Server 2003");
}
else if (osInfo.dwMajorVersion == 5 && osInfo.dwMinorVersion == 1)
printf("Windows XP");
else if (osInfo.dwMajorVersion == 5 && osInfo.dwMinorVersion == 0)
printf("Windows 2000");
else
printf("Unknown");
return 0;
}
```
该程序使用`GetVersionEx`函数获取操作系统版本信息,并通过判断版本号和产品类型来确定具体的Windows系统版本。在输出结果时,每个版本对应着相应的消息进行打印。
### 回答3:
下面是一个使用C语言编写的示例程序,用于判断Windows系统的版本。
```c
#include <windows.h>
#include <stdio.h>
int main()
{
// 获取操作系统版本信息
OSVERSIONINFOW osVersion;
osVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW);
if (GetVersionExW(&osVersion))
{
// 判断Windows系统版本
if (osVersion.dwMajorVersion == 5 && osVersion.dwMinorVersion == 0)
{
printf("Windows 2000\n");
}
else if (osVersion.dwMajorVersion == 5 && osVersion.dwMinorVersion == 1)
{
printf("Windows XP\n");
}
else if (osVersion.dwMajorVersion == 5 && osVersion.dwMinorVersion == 2)
{
printf("Windows Server 2003\n");
}
else if (osVersion.dwMajorVersion == 6 && osVersion.dwMinorVersion == 0)
{
printf("Windows Vista\n");
}
else if (osVersion.dwMajorVersion == 6 && osVersion.dwMinorVersion == 1)
{
printf("Windows 7\n");
}
else if (osVersion.dwMajorVersion == 6 && osVersion.dwMinorVersion == 2)
{
printf("Windows 8\n");
}
else if (osVersion.dwMajorVersion == 6 && osVersion.dwMinorVersion == 3)
{
printf("Windows 8.1\n");
}
else if (osVersion.dwMajorVersion == 10 && osVersion.dwMinorVersion == 0)
{
printf("Windows 10\n");
}
else
{
printf("Unknown Windows Version\n");
}
}
else
{
printf("Failed to get OS version\n");
}
return 0;
}
```
该程序使用了Windows提供的API函数`GetVersionExW`获取操作系统版本信息,然后根据版本号进行判断,输出相应的提示信息。
阅读全文