[英]How to read the Steam Install Path from the Windows Registry?
我正在尝试开发一个简单的Python
程序来自动检测steam
安装文件夹的位置。
我知道可以在以下路径的注册表中找到此信息:
Computer\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Valve\Steam
例如:
如何从InstallPath
REG_SZ
读取信息以获得:
C:\Program Files (x86)\Steam
如果有人可以提供帮助,那就太好了
您可以使用[Python 3.Docs]:winreg - Windows 注册表访问。
虽然这个问题缺乏任何你自己解决问题的尝试,但这里有一个例子:
>>> import sys >>> import winreg >>> >>> try: ... hkey = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\WOW6432Node\Valve\Steam")... except: ... hkey = None... print(sys.exc_info())... >>> hkey <PyHKEY object at 0x00000154FF5D0390> >>> >>> try: ... steam_path = winreg.QueryValueEx(hkey, "InstallPath")... except: ... steam_path = None... print(sys.exc_info())... >>> steam_path ('C:\\Program Files (x86)\\Steam', 1) >>> steam_path[0] 'C:\\Program Files (x86)\\Steam' >>> steam_path[1] == winreg.REG_SZ True >>> >>> winreg.CloseKey(hkey)
备注:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.