我正在创建一个python脚本来查找在注册表中的卸载文件夹中安装的程序,该脚本在32位计算机上运行得非常好,但在64位计算机上出现wmi错误。 无法获取64位上python的wmi模块机器。是有一个吗? 请忽略缩进错误。 我在某论坛上发现了这个剧本,很抱歉没有给予相应的作者应有的信任
r = wmi.Registry()
result, names = r.EnumKey (hDefKey=HKEY_LOCAL_MACHINE, sSubKeyName=r"Software\Microsoft\Windows\CurrentVersion\Uninstall")
separator = "*" * 80
keyPath = r"Software\Microsoft\Windows\CurrentVersion\Uninstall"
for subkey in names:
try:
path = keyPath + "\\" + subkey
key = OpenKey(HKEY_LOCAL_MACHINE, path, 0, KEY_ALL_ACCESS)
try:
temp = QueryValueEx(key, 'DisplayName')
temp1 = QueryValueEx(key, 'DisplayVersion')
temp2 = QueryValueEx(key, 'Publisher')
display = str(temp[0])
display_ver=str(temp1[0])
display_p=str(temp2[0])
print ('Display Name: ' + display + '\nDisplay version: ' + display_ver + '\nVendor/Publisher: ' + display_p +'\nRegkey: ' + subkey + '\n')
except:
print ('Regkey: ' + subkey + '\n')
except:
fp = StringIO.StringIO()
traceback.print_exc(file=fp)
errorMessage = fp.getvalue()
#error = 'Error for ' + key + '. Message follows:\n' + errorMessage
#HelperFuncs.LogError(error)
这可能不是使用this实现的最好的代码,但它适用于我的应用程序。我希望你能用它或改进它。在
示例结果如下:
^{pr2}$结果确保始终存在显示名称。考虑到我对Python还不熟悉,这个问题很难解决。但是不管怎样,如果某个应用程序在值列表中没有显示名称,它将使用最后一个键地址作为显示名称。在
尝试使用_winreg而不是wmi,我相信64位的注册表树略有不同,它将32位和64位应用程序分开,因此您可能需要枚举2个注册表树。在
相关问题 更多 >
编程相关推荐