如何检测用户操作系统

发布于 2025-01-04 13:34:19 字数 1196 浏览 0 评论 0原文

我正在编写一个应用程序,需要在其中创建日志,我必须检测用户使用的操作系统。基本上,我是通过检查操作系统版本来执行此操作,但问题是 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 + ")");
}

I am writing a application in which I need to create log for this I have to detect the OS that user using.Basically I am doing this from check OS version but the issue is both Windows Vista and Windows Server 2008 has the same version ie 6.0.So there is any other method to find the OS of user.

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 + ")");
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

海未深 2025-01-11 13:34:19

也许您可以阅读这篇 stackoverflow 帖子 Detect Windows version in .net 或者这篇文章可以提供帮助你http://andrewensley.com/2009/06/c-detect-windows-os-part-1/

最诚挚的问候

Perhaps You could read this stackoverflow post Detect Windows version in .net or this article could help you http://andrewensley.com/2009/06/c-detect-windows-os-part-1/

Best regards

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文