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.
What used to be called simply “the value of a registry key” (for since there was only one, there was no need to give it a name) now goes by the special name the default value: It's the value whose name is null. There's nothing particularly special about the default value aside from its unusual name.
Use the GetValue method, specifying the path and name) to read a value from registry key. The following example reads the value Name from HKEY_CURRENT_USER\Software\MyApp and displays it in a message box.
The so called default value is really an unnamed value but RegEdit always displays it as " (Default)". The presence of an assigned, i.e. non null, default value can be detected by looking for an empty string, i.e. "", in the array returned by RegistryKey.GetValueNames ().
Registry. Get Value (String, String, Object) Method Microsoft. Win32 Retrieves the value associated with the specified name, in the specified registry key. If the name is not found in the specified key, returns a default value that you provide, or null if the specified key does not exist.
A registry key can have one value that is not associated with any name. When this unnamed value is displayed in the registry editor, the string "(Default)" appears instead of a name. To retrieve this unnamed value, specify either null or the empty string ("") for name.
See How to Open Registry Editor if you need help. On the left side of the editor, navigate to the registry key that you want to add another key to, usually referred to as a subkey, or the key you want to add a value to. You can't add additional top-level keys to the registry.
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)'
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With