如何使用 Squish QT 确定 Python 中的 Windows 版本?

发布于 2024-12-12 07:32:40 字数 199 浏览 3 评论 0原文

有人知道如何确定 Windows 版本吗?

例如,对于 32 位和 64 位 Windows: - Windows XP 家庭版/专业版 - Windows Vista 商业版/旗舰版...等 - Windows 7 家庭普通版/家庭高级版/专业版/旗舰版...等

我想知道是否可以从注册表或 Python API 检索此信息?

谢谢。

Anyone know how to determine the Windows Edition ??

E.g. for both 32bit and 64bit of Windows:
- Windows XP Home/Professional
- Windows Vista Business/Ultimate...etc
- Windows 7 Home Basic/Home Premium/Professional/Ultimate...etc

I wonder if could retrieve this info from registry or Python API ??

Thanks.

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

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

发布评论

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

评论(2

指尖凝香 2024-12-19 07:32:40

如果 ctypes 不起作用(由于 32 位与 64 位?),这个 hack 应该:

def get_Windows_name():
    import subprocess, re
    o = subprocess.Popen('systeminfo', stdout=subprocess.PIPE).communicate()[0]
    try: o = str(o, "latin-1")  # Python 3+
    except: pass  
    return re.search("OS Name:\s*(.*)", o).group(1).strip()

print(get_Windows_name())

或者只是读取注册表:

try: import winreg
except: import _winreg as winreg
with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\Microsoft\Windows NT\CurrentVersion") as key:
    print(winreg.QueryValueEx(key, "EditionID")[0])

或者使用这个:

from win32com.client import GetObject
wim = GetObject('winmgmts:')
print([o.Caption for o in wim.ExecQuery("Select * from Win32_OperatingSystem")][0])

If ctypes doesn't work (due to 32 vs 64 bits?), this hack should:

def get_Windows_name():
    import subprocess, re
    o = subprocess.Popen('systeminfo', stdout=subprocess.PIPE).communicate()[0]
    try: o = str(o, "latin-1")  # Python 3+
    except: pass  
    return re.search("OS Name:\s*(.*)", o).group(1).strip()

print(get_Windows_name())

Or just read the registry:

try: import winreg
except: import _winreg as winreg
with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\Microsoft\Windows NT\CurrentVersion") as key:
    print(winreg.QueryValueEx(key, "EditionID")[0])

Or use this:

from win32com.client import GetObject
wim = GetObject('winmgmts:')
print([o.Caption for o in wim.ExecQuery("Select * from Win32_OperatingSystem")][0])
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文