我可以依赖 OSVERSIONINFO.szCSDVersion 或 Environment.OSVersion.ServicePack 始终采用“Service Pack X”形式吗?

发布于 2024-12-10 18:53:04 字数 617 浏览 0 评论 0原文

标题基本上说明了一切。我需要确定 Windows Service Pack 编号(以数字形式),以及 Environment.OSVersion.ServicePack (基本上只返回 OSVERSIONINFO.szCSDVersion) 仅返回一个字符串。

在我的所有测试中,该字符串的格式为 ""(无服务包)或 "Service Pack X",其中包含 X 是一个数字。所以解析这个的算法应该非常简单。

我的问题:我可以依赖这个字符串来始终具有这种格式吗?

(我的一部分说不,因为它没有记录。另一部分说可以,因为肯定很多现有代码会破坏如果 MS 决定返回 Windows 7 SP2 的“SP 2 (x86)”,那么他们不会这样做。)

The title basically says it all. I need to determine the Windows Service Pack number (in numeric form), and Environment.OSVersion.ServicePack (which basically just returns OSVERSIONINFO.szCSDVersion) just returns a string.

In all my tests, this string turned out to be in the form "" (no service pack) or "Service Pack X", with X being a number. So the algorithm to parse this should be quite simple.

My question: Can I rely on this string to always have this format?

(One part of me says no, beause it's not documented. The other part says yes, because surely a lot of existing code would break if MS would decide to return, say, "SP 2 (x86)" for Windows 7 SP2. Thus, they won't do it. Does anyone have more information on that?)

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

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

发布评论

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

评论(2

删除会话 2024-12-17 18:53:04

不,你不能,某些版本使用翻译字符串!如果您查看该链接中图像中的字符串,您会发现只需使用在字符串中找到的第一个数字即可。

OSVERSIONINFOEX是在NT4 SP6中添加的,如果你调用GetVersionEx你只需要在Win9x上处理字符串和<; NT4 SP6 并在其他系统上使用 OSVERSIONINFOEX.wServicePackMajor。

No you can't, some versions use translated strings! If you look at the strings from the image in that link you see that you might get away with just using the first number you find in the string.

OSVERSIONINFOEX was added in NT4 SP6, if you call GetVersionEx you only need to deal with the string on Win9x and < NT4 SP6 and use OSVERSIONINFOEX.wServicePackMajor on other systems.

长发绾君心 2024-12-17 18:53:04

您应该使用 BuildLabEx 来代替。它具有自 Windows 早期版本以来一直沿用的指定格式。不确定是否可以在 WMI 中找到它(应该可以),但它位于注册表中:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\BuildLabEx

示例:

7601.17640.amd64fre .win7sp1_gdr.110632-1508

如果它让您感觉更舒服,您可以信赖为了简单起见,最初在 CSDVersion 上匹配某个正则表达式,如果不匹配,则故障返回到 BuildLabEx

You should use BuildLabEx instead. It has a specified format which has held since early builds of Windows. Not sure if you can find it in WMI (you should be able to), but it's in the registry:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\BuildLabEx

Example:

7601.17640.amd64fre.win7sp1_gdr.110632-1508

If it makes you feel more comfortable, you could rely initially on CSDVersion matching a certain regex for simplicity, and fail back onto BuildLabEx if it doesn't match.

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