Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve (Default) Value in Registry key

How can I get the (Default) registry value?

For this key: HKCR\http\shell\open\command\ the values are below.

enter image description here

I was using:

Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice\" |% {$_.ProgId}

to get value of ProgId

enter image description here

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.

like image 439
Imsa Avatar asked Jul 29 '15 20:07

Imsa


People also ask

What is default value of registry key?

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.

How do I read registry values?

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.

How to find the default value of a registry key?

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 ().

How do I get the value of a string in Windows Registry?

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.

How do I retrieve an unnamed value from a registry key?

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.

How do I add a value to a registry key?

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.


2 Answers

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)'
like image 197
CB. Avatar answered Sep 28 '22 00:09

CB.


  1. 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)"
    
  2. 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

like image 20
papo Avatar answered Sep 28 '22 00:09

papo