使用 PowerShell 查找所有已安装的应用程序?
我正在尝试使用 Windows PowerShell 2.0 查找已安装的应用程序。我尝试了两种方法,一种使用 WMI,一种使用注册表。这两种方法都能够调出大量已安装的应用程序和组件,但是似乎没有一种方法调出我感兴趣的应用程序。
我专门寻找 CruiseControl.NET。它出现在“程序和功能”控制面板小程序的应用程序列表中。我知道它当前已安装,因为我刚刚卸载并重新安装它以重新开始。然而,以下两种方法似乎都不起作用(它们成功,但不返回任何结果):
注册表搜索方法
在注册表中查找HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall 应用程序密钥。如果我删除 where,会返回很多内容,但它丢失了很多出现在 Windows 程序和功能控制面板中的应用程序。
gci "hklm:\software\microsoft\windows\currentversion\uninstall"
| foreach { gp $_.PSPath }
| select DisplayVersion,InstallDate,ModifyPath,Publisher,UninstallString,Language,DisplayName
| where { $_.DisplayName -match "^Cruise*" }
WMI 方法
也返回大量内容,但是,根据 Win32_Product 对象的文档,它们只是 MSI 安装的应用程序。我猜很多应用程序都丢失了,因为它们不是 MSI。 CruiseControl.NET 安装程序是 NSIS(NullSoft 安装系统)...因为它没有出现在这里,我猜测它根本不使用 MSI,但是我很好奇是否有另一种方法可以使用 WMI查找任何/所有已安装的应用程序,无论它们是否使用 MSI。
gwmi -namespace "root\cimv2" -class "Win32_Product"
| select Name,Vendor,Version,IdentifyingNumber
| where { $_.Name -match "^Cruise*" }
通过注册表查找应用程序对我来说确实没有多大好处。除非它还提供某种方法来查找应用程序卸载程序以及调用它的正确参数,但情况似乎并非总是如此。我更喜欢使用 WMI 来查找和卸载我需要卸载的应用程序,因为这不仅允许我对所有脚本 (WMI) 使用单个管理界面,而且其他人应该很容易弄清楚如何卸载以便将来维护这些脚本,因为 WMI 通常都有详细的文档记录。
I am trying to use Windows PowerShell 2.0 to find an installed application. I have tried two methods, one using WMI and one using the Registry. Both methods are able to bring up a large list of installed applications and components, however neither one seems to bring up the application I am interested in.
I am specifically looking for CruiseControl.NET. It appears in the list of applications in the Programs and Features control panel applet. I know for a fact that it is currently installed, since I just uninstalled and reinstalled it to start fresh. Neither of the following methods seem to work, however (they succeed, but return no results):
Registry Search Approach
Looks in the registry HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
for application keys. Returns plenty if I remove the where, but it is missing quite a few applications that do appear in the windows programs and features control panel.
gci "hklm:\software\microsoft\windows\currentversion\uninstall"
| foreach { gp $_.PSPath }
| select DisplayVersion,InstallDate,ModifyPath,Publisher,UninstallString,Language,DisplayName
| where { $_.DisplayName -match "^Cruise*" }
WMI Approach
Also returns plenty, however, based on the documentation for the Win32_Product object, they are only MSI installed applications. Many applications are missing, I'm guessing because they are not MSI. The CruiseControl.NET installer is the NSIS (NullSoft Installation System)...since it doesn't appear here, I am guessing that it doesn't use MSI at all, however I am curious if there is another way to use WMI to find ANY/ALL installed applications, regardless of whether they used MSI or not.
gwmi -namespace "root\cimv2" -class "Win32_Product"
| select Name,Vendor,Version,IdentifyingNumber
| where { $_.Name -match "^Cruise*" }
Finding the application via the registry does not do me a whole lot of good, really. Unless it also provides some way to find the applications uninstaller and the correct parameters to invoke it, which does not appear to always be the case. I would prefer to use WMI to find and uninstall the applications I need to uninstall, as that would not only allow me to use a single management interface for all of my scripts (WMI), but it should be easy for others to figure out how to maintain the scripts in the future since WMI is generally well documented.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
好吧,很抱歉再次这样做。我有一个坏习惯,就是自己回答问题。
不管怎样,我通过在注册表中搜索“CruiseControl.NET”找到了问题的答案。 64 位版本的 Windows 似乎将卸载信息存储在多个位置。最值得注意的是,卸载信息似乎主要聚集在以下键上:
我能够找到此处列出的系统上的每个程序,包括 CruiseControl.NET。请注意,这似乎仅适用于 64 位 Windows 系统。
Well, sorry to do this again. I had a bad habit of answering my own questions.
Anyway, I found the answer to my question by searching the registry for "CruiseControl.NET". It seems that 64bit versions of windows store Uninstall information in multiple places. Most notably, uninstall information seems to be primarily aggregated at the following key:
I was able to find every program on my system listed here, including CruiseControl.NET. Note that this only seems to be the case on 64bit Windows Systems.
我在网上发现这很神奇,在管理模式下使用
Get-WMIObject Win32_InstalledWin32Program |选择名称、版本、ProgramId
I found this online it's magic, use in admin mode
Get-WMIObject Win32_InstalledWin32Program | select Name, Version, ProgramId
以下命令找到 CruiseControl.Net:
我无法诚实地回答您在搜索卸载注册表时 UninstallString 是否始终存在的问题,也无法告诉您是否会找到计算机上安装的所有应用程序。我知道此处 MS 提供了有关手动卸载的说明,该说明使用此注册表项中的 UninstallString,所以..我确信对此主题有更多了解的人会发表评论..
编辑: Windows 7 计算机上的结果
The below command finds CruiseControl.Net:
I can't honestly answer you about if the UninstallString is always present when searching the Uninstall Registry, nor can I tell you if you will find all applications installed on your machine. I know here MS gives instructions on a manual uninstall, which uses the UninstallString from this registry entry, so.. I am sure someone with more knowledge on the subject will comment..
Edit: Results on a Windows 7 Machine
我正在使用这样的 PowerShell 命令列出所有已安装的软件(32 位/64 位)。
在我的例子中,WMI 对象列表丢失,例如 Nvidia 安装的软件。
并且 Slack 和团队被添加到 HKCU 属性中:
I am using such PowerShell command to list all installed software (both 32bit/64bit).
In my case WMI object list was missing for example Nvidia installed software.
And Slack and teams are added to HKCU property: