Reputation: 1125
How can I get the (Default)
registry value?
For this key: HKCR\http\shell\open\command\
the values are below.
I was using:
Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice\" |% {$_.ProgId}
to get value of ProgId
Now I am trying to get the value of (Default)
in top picture, but replacing {$_.ProgId}
with {$_."(default)"}
does not return anything and ps >
comes back.
Upvotes: 10
Views: 23733
Reputation: 11
For me, it finally worked when I added single quote marks around the registry key value:
(Get-ItemProperty 'Registry::HKEY_CLASSES_ROOT\CLSID\{00020810-0000-0000-C000-000000000046}\DefaultIcon')."(Default)"
--> (result below) <---
C:\Program Files\Microsoft Office\Root\Office16\EXCEL.EXE,1
Upvotes: 1
Reputation: 856
Although this has not been asked by the OP the following command might be helpful because it shows how easy it can be to search all (default) entries of all keys below a hive:
dir HKLM:\SOFTWARE\ -Recurse -ErrorAction Ignore |
Get-ItemProperty -Name "(default)" -ErrorAction Ignore |
Where-Object "(Default)" -like "*ocx" |
Select-Object "(default)", PsPath
The command searches all registered OCX files in HKLM.
Since the output is not very readable I'll choose Convert-Path to make the registry path more readable:
dir HKLM:\SOFTWARE\ -Recurse -ErrorAction Ignore |
Get-ItemProperty -Name "(default)" -ErrorAction Ignore |
Where-Object "(Default)" -like "*ocx" |
Select-Object @{n="OcxPath";e={$_."(default)"}},@{n="Regpath";e={Convert-Path $_.PsPath}}
Upvotes: 4
Reputation: 1989
If you want to use HKCR, to check for Classes in both HKCU and HKLM, you don't need to create a PSDrive, but use:
(Get-ItemProperty Registry::HKCR\http\shell\open\command)."(Default)"
# OR
(Get-ItemProperty Registry::HKEY_CLASSES_ROOT\http\shell\open\command)."(Default)"
Another way, which in some cases might be easier, is to use Method of RegistryKey object:
(Get-Item -Path Registry::HKCR\http\shell\open\command).GetValue("")
# OR
(Get-Item -Path Registry::HKEY_CLASSES_ROOT\http\shell\open\command).GetValue("")
This can also be used on results from Get-ChildItem Cmdlet
Upvotes: 10
Reputation: 60958
maybe this can help:
(get-itemproperty -literalpath HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice).'(default)'
remember that if the value is not set it returns $null
then also your method return the correct value ;)
Forgot to say that HKCR
is not defined at default, use:
New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT
then you can do correctly:
(get-itemproperty -literalpath HKCR:\http\shell\open\command\).'(default)'
Upvotes: 13