谁会用C语言获取操作系统版本号,计算机名啊?
答案:1 悬赏:50 手机版
解决时间 2021-04-13 04:49
- 提问者网友:星軌
- 2021-04-12 17:08
谁会用C语言获取操作系统版本号,计算机名啊?
最佳答案
- 五星知识达人网友:举杯邀酒敬孤独
- 2021-04-12 17:54
GetUserName(LPWSTR lpBuffer, LPDWORD nSize);
lpBuffer是一个数组的地址,用来存贮得到的用户名,nsize是个指针,指向此存贮此数组大小的单元,就是数组能存贮的字符数量
GetVersionExW(LPOSVERSIONINFOW);
参数LPOSVERSIONINFO是一个指向OSVERSIONINFO类型变量的指针,
具体判断代码如下
定义 OSVERSIONINFO osvi;
然后调用函数取得版本号,判断如下
switch (osvi.dwPlatformId)
{
case VER_PLATFORM_WIN32_NT:
if (osvi.dwMajorVersion == 5&&osvi.dwMinorVersion == 0)
{
strOSVersion = TEXT("Windows 2000");
}
else if (osvi.dwMajorVersion == 5&&osvi.dwMinorVersion == 1)
{
strOSVersion = TEXT("Windows XP");
}
else if(osvi.dwMajorVersion == 6&&osvi.dwMinorVersion == 0)
{
strOSVersion = TEXT("Windows Vista");
}
else if (osvi.dwMajorVersion == 4&&osvi.dwMinorVersion == 0)
{
strOSVersion = TEXT("Windows NT");
}
break;
case VER_PLATFORM_WIN32_WINDOWS:
if (osvi.dwMajorVersion == 4&&osvi.dwMinorVersion == 10)
{
strOSVersion = TEXT("Windows 98");
}
else if (osvi.dwMajorVersion == 4&&osvi.dwMinorVersion == 90)
{
strOSVersion = TEXT("Windows ME");
}
else
{
strOSVersion = TEXT("Windows 95");
}
break;
default:
break;
}
lpBuffer是一个数组的地址,用来存贮得到的用户名,nsize是个指针,指向此存贮此数组大小的单元,就是数组能存贮的字符数量
GetVersionExW(LPOSVERSIONINFOW);
参数LPOSVERSIONINFO是一个指向OSVERSIONINFO类型变量的指针,
具体判断代码如下
定义 OSVERSIONINFO osvi;
然后调用函数取得版本号,判断如下
switch (osvi.dwPlatformId)
{
case VER_PLATFORM_WIN32_NT:
if (osvi.dwMajorVersion == 5&&osvi.dwMinorVersion == 0)
{
strOSVersion = TEXT("Windows 2000");
}
else if (osvi.dwMajorVersion == 5&&osvi.dwMinorVersion == 1)
{
strOSVersion = TEXT("Windows XP");
}
else if(osvi.dwMajorVersion == 6&&osvi.dwMinorVersion == 0)
{
strOSVersion = TEXT("Windows Vista");
}
else if (osvi.dwMajorVersion == 4&&osvi.dwMinorVersion == 0)
{
strOSVersion = TEXT("Windows NT");
}
break;
case VER_PLATFORM_WIN32_WINDOWS:
if (osvi.dwMajorVersion == 4&&osvi.dwMinorVersion == 10)
{
strOSVersion = TEXT("Windows 98");
}
else if (osvi.dwMajorVersion == 4&&osvi.dwMinorVersion == 90)
{
strOSVersion = TEXT("Windows ME");
}
else
{
strOSVersion = TEXT("Windows 95");
}
break;
default:
break;
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯