windows WMI“已安装”查询与添加/删除程序列表不同?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/673233/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 06:10:38  来源:igfitidea点击:

WMI "installed" query different from add/remove programs list?

windowswindows-installerwmi

提问by romandas

Trying to use WMI to obtain a list of installed programs for Windows XP. Using wmic, I tried:

尝试使用 WMI 获取 Windows XP 的已安装程序列表。使用 wmic,我试过:

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?

我得到了许多已安装程序的列表,但是在根据“添加/删除程序”显示的内容清理此列表后,我看到添加/删除程序的 GUI 中列出的程序比 WMI 查询中列出的程序多。我需要使用另一个 WMI 查询来安装其余程序吗?或者还有其他地方我需要寻找其他地方吗?

Also, there are two installed programs that are listed in the WMI query that aren't in Add/Remove programs. Any idea why?

此外,WMI 查询中列出的两个已安装程序不在添加/删除程序中。知道为什么吗?

采纳答案by Rob Haupt

I believe your syntax is using the Win32_ProductClass in WMI. One cause is that this class only displays products installed using Windows Installer (See Here). The Uninstall Registry Keyis your best bet.

我相信您的语法使用WMI 中的Win32_Product类。一个原因是此类仅显示使用 Windows Installer 安装的产品(请参阅此处)。该卸载注册表项是您最好的选择。

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\UninstallHKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\UninstallHKEY_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.

在我看来,查看注册表项是最好的方法。

回答by BobbyShaftoe

All that Add/Remove Programs is really doing is reading this Registry key:

所有添加/删除程序真正做的就是阅读这个注册表项:

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall

回答by saalehr

Besides the most commonly known registry key for installed programs:

除了最常见的已安装程序的注册表项:

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall

wmic command and the add/remove programs also query another registry key:

wmic 命令和添加/删除程序还会查询另一个注册表项:

HKEY_CLASSES_ROOT\Installer\Products

HKEY_CLASSES_ROOT\安装程序\产品

Software name shown in the list is read from the Value of a Data entry within this key called: ProductName

列表中显示的软件名称是从名为以下项的数据条目的值中读取的: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.

从上述两个位置删除某个产品的注册表项将使其不会显示在添加/删除程序列表中。这不是卸载程序的方法,它只会从 Windows 已知的已安装软件中删除该条目。

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.

因为,通过使用这种方法,您将失去使用添加/删除列表中的删除按钮从系统中彻底删除软件的机会;建议在删除注册表项之前将其导出到文件中。将来,如果您决定将该项目带回列表,您只需运行您存储的注册表文件。

回答by Tyler Collier

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

我一直在使用 Inno Setup 作为安装程序。我只使用 64 位 Windows 7。我发现正在写入注册表项

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall

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.

我还没有弄清楚如何让 WMI 报告这个列表(尽管该程序在程序和功能中列为已安装)。如果我弄明白了,我会尽量记得在这里报告。

UPDATE:

更新:

Entries for 32-bit programs installed on a 64-bit machine go in that registry location. There's more written here:

安装在 64 位计算机上的 32 位程序的条目位于该注册表位置。还有更多写在这里:

http://mdb-blog.blogspot.com/2010/09/c-check-if-programapplication-is.html

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:

请参阅我在同一帖子中描述 32 位与 64 位行为的评论:

http://mdb-blog.blogspot.com/2010/09/c-check-if-programapplication-is.html?showComment=1300402090679#c861009270784046894

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.

不幸的是,似乎没有办法让 WMI 列出添加/删除程序列表中的所有程序(也就是 Windows 7 中的程序和功能,对 Vista 不确定)。我当前的代码已经放弃了 WMI,转而使用注册表。查询注册表的代码本身比使用 WMI 更容易。示例代码在上面的链接中。

回答by quantme

Not the best, but whether it is practical method:

不是最好的,但是否是实用的方法:

Use HiHymanThis.

使用HiHymanThis

Run hiHyman this, click the "Open the Misc Tools section" button

运行劫持这个,点击“打开其他工具部分”按钮

HiHymanThis Main Menu

HiHymanThis 主菜单

click "Open Uninstall Manager"

点击“打开卸载管理器”

HiHymanThis Configuration

劫持此配置

click save list (*.txt), yes to the prompts, notepad will open with your add/remove programs list.

单击保存列表 (*.txt),对提示是,记事本将打开您的添加/删除程序列表。

HiHymanThis Add/Remove Programs Manager

HiHymanThis 添加/删除程序管理器



Source

来源

回答by Hackoo

You can get it in one line with powershell and batch file :

您可以使用 powershell 和批处理文件在一行中获取它:

@echo off
Powershell /command "Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | Format-List"
Pause

回答by motobói

You can use the script from http://technet.microsoft.com/en-us/library/ee692772.aspx#EBAAto access the registry and list applications using WMI.

您可以使用http://technet.microsoft.com/en-us/library/ee692772.aspx#EBAA 中的脚本访问注册表并使用 WMI 列出应用程序。

回答by MacG

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:

已安装的产品由已安装的软件元素和功能组成,因此值得检查产品的 wmic 别名以及检查 SOFTWAREELEMENT 和 SOFTWAREFEATURE:

wmic product get name,version

wmic softwareelement get name,version

wmic softwarefeature get name,version

回答by candritzky

Add/Remove Programs also has to look into this registry key to find installations for the current user:

添加/删除程序还必须查看此注册表项以查找当前用户的安装:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall

Applications like Google Chrome, Dropbox, or shortcuts installed through JavaWS (web start) JNLPs can be found only here.

只能在此处找到 Google Chrome、Dropbox 或通过 JavaWS(网络启动)JNLP 安装的快捷方式等应用程序。

回答by Ilya Kogan

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.

为了构建一个或多或少可靠的应用程序列表,这些应用程序出现在控制面板的“程序和功能”中,您必须考虑并非所有应用程序都是使用 MSI 安装的。WMI 仅提供随 MSI 安装的那些。

Here is a short summary of what I've found out:

以下是我发现的简短摘要:

MSI applicationsalways have a Product Code (GUID) subkey under HKLM\...\Uninstalland/or under HKLM\...\Installer\UserData\S-1-5-18\Products. In addition, they may have a key that looks like HKLM\...\Uninstall\NotAGuid.

MSI 应用程序始终在HKLM\...\Uninstall和/或 下有一个产品代码 (GUID) 子项HKLM\...\Installer\UserData\S-1-5-18\Products。此外,他们可能有一个看起来像 的键HKLM\...\Uninstall\NotAGuid

Non-MSI applicationsdo not have a product code, and therefore have keys like HKLM\...\Uninstall\NotAGuidor HKCU\...\Uninstall\NotAGuid.

非 MSI 应用程序没有产品代码,因此具有类似HKLM\...\Uninstall\NotAGuid或 的键HKCU\...\Uninstall\NotAGuid