python 获取SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18下的程序列表
时间: 2023-07-09 12:53:35 浏览: 175
你可以使用 Python 的 _winreg 模块来访问 Windows 注册表并获取 SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18下的程序列表。以下是一个示例代码:
```python
import _winreg
# 打开注册表项
key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,
r'SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18')
# 遍历所有子键
i = 0
while True:
try:
subkey_name = _winreg.EnumKey(key, i)
subkey = _winreg.OpenKey(key, subkey_name)
# 获取程序名称和版本信息
name, _ = _winreg.QueryValueEx(subkey, 'DisplayName')
version, _ = _winreg.QueryValueEx(subkey, 'DisplayVersion')
print(name + ' ' + version)
i += 1
except WindowsError:
break
# 关闭注册表项
_winreg.CloseKey(key)
```
这段代码会遍历 SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18下的所有子键,并获取每个程序的名称和版本信息。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)