如何获取Windows中的操作系统名称、版本?
在以下方面哪一个更好地获取操作系统名称、Windows 操作系统版本 -
- 中的信息兼容性的时间
- 获取所有 Windows 操作系统(如 xp、vista 和更高版本的
systeminfo 或 wmic 命令) ?我想避免在 C 中使用 OSVersionInfoEx,因为必须对营销名称检测进行硬编码,并且如果引入新风格的 Windows,则会增加维护工作。请分享您的意见。
Which one is better in following aspects to get OS name, OS version in windows -
- time in getting information
- compatibility in all windows OS like xp, vista and higher
systeminfo or wmic command? I wanted to avoid the use of OSVersionInfoEx in C as one has to hardcode the marketing name detection and will add to maintenance work if new flavour of windows gets introduced. Please share your opinion.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
GetVersionEx - 获取基本操作系统版本号的速度没有比这更快的了。但你是对的,你将无法将较新版本的操作系统映射到正确的字符串。您是否考虑过这样做:
WMI - 需要编写更多代码。但是您可能只在应用程序启动时(或需要时)执行此操作,并在再次需要信息时缓存结果。应用程序查询一次后,操作系统产品名称不会改变。 :) 至于向后兼容性,我确信它在较旧的操作系统上运行良好......但是您将在将其交付给客户之前对其进行测试,对吧?
如果您想要一种未记录的方式,有一个注册表项恰好包含您想要的内容:
GetVersionEx - You can't get any faster than this for getting a basic os version number. But you are right, you won't be able to map newer versions of the OS to the correct string. Have you considered just doing this:
WMI - A bit more code to write. But you could likely just do this at app startup (or when it's needed) and cache the result if the information is needed again. It's not like the operating system product name will change after the app has queried for it once. :) As to backwards compatibility, I'm sure it work fine on older operating systems... but you are going to test it before shipping it to the customer, right?
If you want an undocumented way, there is a registry key that has exactly what you want in it: