如果 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])