有谁知道如何确定Windows版??
例如,适用于32位和64位Windows:- Windows XP家庭版/专业版- Windows Vista商用版/旗舰版...等- Windows 7家庭普通版/家庭高级版/专业版/旗舰版...等
我想知道是否可以从注册表或Python API中检索此信息??
谢谢。
发布于 2011-11-03 00:47:59
如果ctype不起作用(由于32和64位?),这个攻击应该是:
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])发布于 2011-10-27 17:20:09
看看platform.win32_ver()吧。另请参阅How to check if OS is Vista in Python?
https://stackoverflow.com/questions/7913914
复制相似问题