WMI“已安装” 查询与添加/删除程序列表不同?
尝试使用 WMI 获取 Windows XP 已安装程序的列表。 使用 wmic,我尝试:
wmic /output:c:\ProgramList.txt product get name,version
并且我得到了许多已安装程序的列表,但是在根据“添加/删除程序”显示的内容擦洗此列表后,我看到添加/删除程序的 GUI 中列出的程序比在“添加/删除程序”中列出的程序多得多。 WMI 查询。 我是否需要使用另一个 WMI 查询来安装其余程序? 或者还有其他地方我需要寻找其余的吗?
此外,WMI 查询中列出了两个已安装的程序,但它们不在“添加/删除程序”中。 知道为什么吗?
Trying to use WMI to obtain a list of installed programs for Windows XP. Using wmic, I tried:
wmic /output:c:\ProgramList.txt product get name,version
and I get a listing of many of the installed programs, but after scrubbing this list against what "Add/Remove Programs" displays, I see many more programs listed in the GUI of Add/Remove Programs than with the WMI query. Is there another WMI query I need to use to get the rest of the programs installed? Or is there some other place I need to look for the rest?
Also, there are two installed programs that are listed in the WMI query that aren't in Add/Remove programs. Any idea why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(14)
我相信您的语法正在使用 Win32_Product 类在 WMI 中。 原因之一是此类仅显示使用 Windows Installer 安装的产品 (请参见此处)。 卸载注册表项是您最好的选择。
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall
HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall
评论更新:
卸载注册表项是列出已安装和未安装内容的标准位置。 “添加/删除程序”列表将使用它来填充应用程序列表。 我确信有些应用程序没有在此位置列出自己。 在这种情况下,您必须求助于另一种更原始的方法,例如搜索“程序文件”目录或在“开始”菜单程序列表中查找。 这两种方式肯定都不理想。
我认为,查看注册表项是最好的方法。
I believe your syntax is using the Win32_Product Class in WMI. One cause is that this class only displays products installed using Windows Installer (See Here). The Uninstall Registry Key is your best bet.
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall
HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall
UPDATE FOR COMMENTS:
The Uninstall Registry Key is the standard place to list what is installed and what isn't installed. It is the location that the Add/Remove Programs list will use to populate the list of applications. I'm sure that there are applications that don't list themselves in this location. In that case you'd have to resort to another cruder method such as searching the Program Files directory or looking in the Start Menu Programs List. Both of those ways are definitely not ideal.
In my opinion, looking at the registry key is the best method.
“添加/删除程序”真正所做的就是读取此注册表项:
All that Add/Remove Programs is really doing is reading this Registry key:
除了最常见的已安装程序注册表项:
wmic 命令和添加/删除程序还会查询另一个注册表项:
列表中显示的软件名称是从此项中名为 ProductName 的数据条目的值读取的。
从上述两个位置删除特定产品的注册表项将使其不再显示在添加/删除中节目列表。 这不是卸载程序的方法,它只是从 Windows 已知的已安装软件中删除该条目。
因为,通过使用此方法,您将失去使用添加/删除列表中的“删除”按钮从系统中彻底删除软件的机会; 建议在删除注册表项之前将其导出到文件中。 将来,如果您决定将该项目重新添加到列表中,您只需运行您存储的注册表文件即可。
Besides the most commonly known registry key for installed programs:
wmic command and the add/remove programs also query another registry key:
Software name shown in the list is read from the Value of a Data entry within this key called: ProductName
Removing the registry key for a certain product from both of the above locations will keep it from showing in the add/remove programs list. This is not a method to uninstall programs, it will just remove the entry from what's known to windows as installed software.
Since, by using this method you would lose the chance of using the Remove button from the add/remove list to cleanly remove the software from your system; it's recommended to export registry keys to a file before you delete them. In future, if you decided to bring that item back to the list, you would simply run the registry file you stored.
我一直在使用 Inno Setup 作为安装程序。 我仅使用 64 位 Windows 7。 我发现注册表项正在被写入
我还没有弄清楚如何让 WMI 报告此列表(尽管该程序在程序和功能中列为已安装)。 如果我弄清楚了,我会尽力记住在这里报告。
更新:
安装在 64 位计算机上的 32 位程序的条目位于该注册表位置。 这里还有更多内容:
http://mdb- blog.blogspot.com/2010/09/c-check-if-programapplication-is.html
请参阅我在同一篇文章中描述 32 位与 64 位行为的评论:
http://mdb-blog.blogspot.com /2010/09/c-check-if-programapplication-is.html?showComment=1300402090679#c861009270784046894
不幸的是,似乎没有办法让 WMI 列出添加/删除程序中的所有程序列表(也称为 Windows 7 中的程序和功能,不确定 Vista 中的程序和功能)。 我当前的代码已放弃 WMI,转而使用注册表。 询问注册表的代码本身甚至比使用 WMI 更容易。 示例代码位于上面的链接中。
I have been using Inno Setup for an installer. I'm using 64-bit Windows 7 only. I'm finding that registry entries are being written to
I haven't yet figured out how to get this list to be reported by WMI (although the program is listed as installed in Programs and Features). If I figure it out, I'll try to remember to report back here.
UPDATE:
Entries for 32-bit programs installed on a 64-bit machine go in that registry location. There's more written here:
http://mdb-blog.blogspot.com/2010/09/c-check-if-programapplication-is.html
See my comment that describes 32-bit vs 64-bit behavior in that same post here:
http://mdb-blog.blogspot.com/2010/09/c-check-if-programapplication-is.html?showComment=1300402090679#c861009270784046894
Unfortunately, there doesn't seem to be a way to get WMI to list all programs from the add/remove programs list (aka Programs and Features in Windows 7, not sure about Vista). My current code has dropped WMI in favor of using the registry. The code itself to interrogate the registry is even easier than using WMI. Sample code is in the above link.
您可以使用 powershell 和批处理文件在一行中获取它:
You can get it in one line with powershell and batch file :
不是最好的,但是否实用的方法:
使用HijackThis。 (旧版本:
HijackThis)运行hijack this,点击“Open “杂项工具”部分”按钮
单击“打开卸载管理器”
单击“保存列表”(*.txt),按照提示“是”,记事本将打开您的添加/删除程序列表。
来源
Not the best, but whether it is practical method:
Use HijackThis. (Old version:
HijackThis)Run hijack this, click the "Open the Misc Tools section" button
click "Open Uninstall Manager"
click save list (*.txt), yes to the prompts, notepad will open with your add/remove programs list.
Source
已安装的产品由已安装的软件元素和功能组成,因此值得检查产品的 wmic 别名以及检查软件和软件特性:
Installed products consist of installed software elements and features so it's worth checking wmic alias's for PRODUCT as well as checking SOFTWAREELEMENT and SOFTWAREFEATURE:
您可以使用 http://technet.microsoft.com/en 中的脚本-us/library/ee692772.aspx#EBAA 使用 WMI 访问注册表并列出应用程序。
You can use the script from http://technet.microsoft.com/en-us/library/ee692772.aspx#EBAA to access the registry and list applications using WMI.
希望这对某人有帮助:我一直在我的脚本中使用基于注册表的枚举(如上面的一些答案所建议的那样),但发现它在通过 SCCM 在 Windows 10 x64 上运行时无法正确枚举 64 位软件(使用 32 位客户端)。 在我的特定情况下,发现这样的解决方案是最直接的解决方案:
意识到这有点太 Perl 风格了,但我见过的所有其他替代方案都涉及包装脚本和类似的聪明解决方案的疯狂,并且这似乎更人性化一点。
PS:我真的很难克制住自己对微软的批评,因为它让一件绝对微不足道的事情变得几乎不可能。 也就是说,枚举网络上使用的所有 MS Office 版本是一项让成年人哭泣的任务。
Hope this helps somebody: I've been using the registry-based enumeration in my scripts (as suggested by some of the answers above), but have found that it does not properly enumerate 64-bit software when run on Windows 10 x64 via SCCM (which uses a 32-bit client). Found something like this to be the most straightforward solution in my particular case:
Realize this is a little too Perl-ish in a bad way, but all other alternatives I've seen involved insanity with wrapper scripts and similar clever-clever solutions, and this seems a little more human.
P.S. Trying really hard to refrain from dumping a ton of salt on Microsoft here for making an absolutely trivial thing next to impossible. I.e., enumerating all MS Office versions in use on a network is a task to make a grown man weep.
自从提出这个问题以来,时间已经过去了很多...
现在有一个 WMI 类可用于注册表中的卸载条目。 这比 Win32_Product 引用要快得多,我认为 Win32_Product 也在列表上运行验证,并且可能需要一段时间才能枚举。 下面的 Powershell 代码(可能需要 Powershell 3 或更高版本)将列出所有条目(Out-Gridview 部分只是为了美观显示)。
With time having moved on quite a bit since this question was asked...
There's a WMI class available these days for the Uninstall entries in the registry. This is much quicker to reference than Win32_Product, which I think also runs verification on the list and can take a while to enumerate. The below Powershell code (possibly requires Powershell 3 or later) will list all entries (The Out-Gridview part is just for a pretty display).
添加/删除程序还必须查看此注册表项以查找当前用户的安装:
Google Chrome、Dropbox 等应用程序或通过 JavaWS(网络启动)JNLP 安装的快捷方式只能在此处找到。
Add/Remove Programs also has to look into this registry key to find installations for the current user:
Applications like Google Chrome, Dropbox, or shortcuts installed through JavaWS (web start) JNLPs can be found only here.
为了构建出现在控制面板的“程序和功能”中的或多或少可靠的应用程序列表,您必须考虑到并非所有应用程序都是使用 MSI 安装的。 WMI 仅提供通过 MSI 安装的。
以下是我发现的内容的简短摘要:
MSI 应用程序 始终在
HKLM\...\Uninstall
和/或下有一个产品代码 (GUID) 子项HKLM\...\Installer\UserData\S-1-5-18\Products
。 此外,他们可能有一个类似于 HKLM\...\Uninstall\NotAGuid 的密钥。非 MSI 应用程序没有产品代码,因此具有诸如
HKLM\...\Uninstall\NotAGuid
或HKCU\...\Uninstall 之类的密钥\NotAGuid
。In order to build a more-or-less reliable list of applications that appear in the "Programs and Feautres" in the Control Panel, you have to consider that not all applications were installed using MSI. WMI only provides the ones installed with MSI.
Here is a short summary of what I've found out:
MSI applications always have a Product Code (GUID) subkey under
HKLM\...\Uninstall
and/or underHKLM\...\Installer\UserData\S-1-5-18\Products
. In addition, they may have a key that looks likeHKLM\...\Uninstall\NotAGuid
.Non-MSI applications do not have a product code, and therefore have keys like
HKLM\...\Uninstall\NotAGuid
orHKCU\...\Uninstall\NotAGuid
.我根据自己的需要改编了 MS-Technet VBScript。 它将 Wow6432Node 以及标准条目转储到“programms.txt”中
使用风险自负,无保修!
另存为 dump.vbs
从命令行输入:wscript dump.vbs
I adapted the MS-Technet VBScript for my needs. It dumps Wow6432Node as well as standard entries into "programms.txt"
Use it at your own risk, no warranty!
Save as dump.vbs
From command line type: wscript dump.vbs
我遇到了同样的问题,WMIC 命令仅显示所有已安装程序的子集。 我需要一个命令来输出 Windows 10 中所有已安装程序的 CSV 文件,并且我想让同事轻松运行。 下面的 Powershell 命令似乎运行良好,运行速度比 WMIC 命令快得多; 它将在用户的 Documents 文件夹中生成一个名为 AppsInstalled.csv 的 CSV 文件,其中的程序按名称排序,并删除空行(在我的测试中,某些程序返回了许多空行)原因?)。
Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | 选择对象显示名称、显示版本、发布者、安装日期| Where-对象显示名称 -ne $null | 排序对象-属性显示名称| Export-Csv“$($env:USERPROFILE)\Documents\AppsInstalled.csv”-NoTypeInformation
I had the same issue with the WMIC command only showing a subset of all installed programs. I needed a command that would output a CSV file of all the installed programs in Windows 10 and I wanted to make it easy for colleagues to run. The following Powershell command seems to work well, running much quicker than the WMIC command; it will generate a CSV in the user's Documents folder called AppsInstalled.csv with programs sorted by name, and with empty lines removed (numerous blank lines were returned in my tests for some reason?).
Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate| Where-Object DisplayName -ne $null | Sort-Object -Property DisplayName | Export-Csv "$($env:USERPROFILE)\Documents\AppsInstalled.csv" -NoTypeInformation