如何获取仅在控制面板「程序和功能」中显示的软件列表?
获取控制面板「程序和功能」可见软件列表的VBScript优化方案
你的原始VBS脚本会遍历HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall下的所有子键,但控制面板的「程序和功能」并不会显示所有这些条目——它会根据几个注册表值过滤掉系统组件、子更新项、隐藏程序等。我们只需要在脚本中加入对应的判断逻辑,就能精准获取可见的软件列表。
关键过滤条件
「程序和功能」会隐藏以下类型的条目:
- 存在
SystemComponent值且值为1的系统组件 - 存在
ParentKeyName值的子组件/更新项(属于某个主程序的附属内容) - 存在
NoRemove值且值为1的不可卸载程序 - 当然还要保留
DisplayName非空的有效条目
修改后的完整代码
Const HKEY_LOCAL_MACHINE = &H80000002 Dim strComputer, strKeyPath Dim objReg, strSubkey, arrSubkeys Dim Name, SystemComponent, ParentKeyName, NoRemove strComputer = "." ' Registry key path of Control panel items for installed programs strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _ strComputer & "\root\default:StdRegProv") objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubkeys 'Enumerate registry keys. For Each strSubkey In arrSubkeys ' 获取DisplayName objReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath & strSubkey, "DisplayName", Name ' 获取SystemComponent(默认0,即非系统组件) objReg.GetDWORDValue HKEY_LOCAL_MACHINE, strKeyPath & strSubkey, "SystemComponent", SystemComponent If IsNull(SystemComponent) Then SystemComponent = 0 ' 获取ParentKeyName(不存在则为空) objReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath & strSubkey, "ParentKeyName", ParentKeyName ' 获取NoRemove(默认0,即可卸载) objReg.GetDWORDValue HKEY_LOCAL_MACHINE, strKeyPath & strSubkey, "NoRemove", NoRemove If IsNull(NoRemove) Then NoRemove = 0 ' 过滤条件:DisplayName非空 + 非系统组件 + 无父键 + 允许卸载 If Name <> "" And SystemComponent = 0 And ParentKeyName = "" And NoRemove = 0 Then WScript.Echo Name End If Next WScript.Echo "已成功列出控制面板「程序和功能」中可见的安装程序。" WScript.Quit
代码改动说明
- 新增了对
SystemComponent、ParentKeyName、NoRemove三个关键值的读取逻辑 - 对可能不存在的注册表值做了默认值处理(比如
SystemComponent不存在时视为0,即非系统组件) - 加入了多条件判断,只输出符合「程序和功能」显示规则的软件名称
- 调整了输出格式,去掉了多余的逗号,让结果更整洁
内容的提问来源于stack exchange,提问作者im_mangesh




