我正在编写一个应用程序,其中我需要为此创建日志我必须检测用户使用的操作系统。基本上我从检查操作系统版本这样做但问题是Windows Vista和Windows Server 2008都有相同的版本即6.0。所以还有其他方法可以找到用户的操作系统。
if (OSInfo.dwMajorVersion == 5 && OSInfo.dwMinorVersion == 1)
{
s.AppendLine("OS Version :" + " " + "Windows XP " + OSInfo.szCSDVersion + " " + "(Build Number : " + OSInfo.dwBuildNumber + ")");
}
else if (OSInfo.dwMajorVersion == 6 && OSInfo.dwMinorVersion == 0 && OSInfo.dwOSVersionInfoSize == 152 ) //&& OSInfo.wProductType != VER_NT_WORKSTATION)
{
s.AppendLine("OS Version :" + " " + "Windows VISTA/Windows Server 2008 " + OSInfo.szCSDVersion + " " + "(Build Number : " + OSInfo.dwBuildNumber + ")");
}
else if (OSInfo.dwMajorVersion == 6 && OSInfo.dwMinorVersion == 1)
{
s.AppendLine("OS Version :" + " " + "Windows7 " + OSInfo.szCSDVersion + " " + "(Build Number :" + OSInfo.dwBuildNumber + ")");
}
else if (OSInfo.dwMajorVersion == 5 && OSInfo.dwMinorVersion == 2)
{
s.AppendLine("OS Version :" + " " + "Windows Server 2003 " + OSInfo.szCSDVersion + " " + "(Build Number :" + OSInfo.dwBuildNumber + ")");
}
答案 0 :(得分:1)
也许您可以阅读此stackoverflow帖子Detect Windows version in .net或者本文可以帮助您http://andrewensley.com/2009/06/c-detect-windows-os-part-1/
祝你好运