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.
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:
HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\
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.
The below command finds CruiseControl.Net:
gci "HKLM:\software\Microsoft\windows\CurrentVersion\Uninstall" | %{ gp $_.PSPath } | where { $_.DisplayName -match "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
PSPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\software\Microsoft\windows\CurrentVersion\Uninstall\CruiseControl.NET
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\software\Microsoft\windows\CurrentVersion\Uninstall
PSChildName : CruiseControl.NET
PSProvider : Microsoft.PowerShell.Core\Registry
NSIS:StartMenuDir : CruiseControl.NET
CCNetVDir : 1
DisplayName : CruiseControl.NET 1.5.6804.1
UninstallString : C:\Program Files\CruiseControl.NET\uninst.exe
DisplayIcon : C:\Program Files\CruiseControl.NET\Server\ccnet.exe
DisplayVersion : 1.5.6804.1
URLInfoAbout : http://ccnet.thoughtworks.com/
Publisher : ThoughtWorks
I found this online it's magic, use in admin mode
Get-WMIObject Win32_InstalledWin32Program | select Name, Version, ProgramId
I am using such PowerShell command to list all installed software (both 32bit/64bit).
Get-ItemProperty -Path "HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*", "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*", "HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*" |where { $_.DisplayName -ne $null } | Select-Object DisplayName, DisplayVersion, InstallDate
In my case WMI object list was missing for example Nvidia installed software.
And Slack and teams are added to HKCU property:
DisplayName : Slack
DisplayVersion : 4.19.3
InstallDate : 20210830
Publisher : Slack Technologies Inc.
PSDrive : HKCU
DisplayName : Microsoft Teams
DisplayVersion : 1.4.00.22976
InstallDate : 20210921
Publisher : Microsoft Corporation
PSDrive : HKCU
精彩评论