如何用C语言获取主机操作系统的版本号
1个回答
2014-10-27
展开全部
redhat系统可直接从文件中读取:cat /etc/redhat-release
windows:
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;
}
windows:
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;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询