Today I was looking for the COM ProgID
for Excel on my machine and my previous approach of using WMI didn’t work.
1 2 |
PS> gwmi Win32_COMSetting | ?{ $_.ProgId -match "Excel" } PS> |
That’s not correct as I can create a new COM object by referring to Excel.Application
.
Since ProgID
s are found in the registry under HKEY_LOCAL_MACHINE\SOFTWARE\Classes
I figured that would be a good place to get an exhaustive list from. Under this key there are three types of subkeys:
- Subkeys for each file extension registered with the system, each of which has a
(Default)
entry with theProgID
and also a subkey with theProgID
. Not all theseProgIDs
seem to be valid though (based on my testing), so it’s best to go by the other set of subkeys detailed below. - Subkeys for each
ProgID
– usually of bothProgID
formats<Program>.<Component>.<Version>
and<Program>.<Component>
– again, not all valid, but a good test of validity (based on my testing) being whether they contain a subkey calledCLSID
. - Subkeys such as “Unknown”, “Undecided”, etc and also some that look like
ProgID
s but are not in the correct format (for instance: they don’t contain the<Component>.<Version>
bit, or contain spaces and underscores (not allowed)
So a sensible way to filter out ProgIDs
seems to be to check for subkeys of the format <Program>.<Component>.<Version>
(the <Version>
being optional) and to further filter out those which have a CLSID
subkey.
Thus we have the following:
1 2 |
Get-ChildItem "HKLM:\SOFTWARE\Classes" | ?{ ($_.PSChildName -match "^[a-z]+\.[a-z]+(\.\d+)?$") -and ($_.GetSubKeyNames() -contains "CLSID") } | ft PSChildName |
And to search for a specific application, one can do:
1 2 3 |
Get-ChildItem "HKLM:\SOFTWARE\Classes" | ?{ ($_.PSChildName -match "^[a-z]+\.[a-z]+(\.\d+)?$") -and ($_.GetSubKeyNames() -contains "CLSID") } | ?{ $_.PSChildName -match "Excel" } | ft PSChildName |