Retrieve (Default) Value in Registry key
Asked Answered
L

3

10

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.

Lecherous answered 29/7, 2015 at 20:50 Comment(0)
I
13

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)'
Insurance answered 29/7, 2015 at 20:58 Comment(3)
Run powershell as administrator and retry.Insurance
If you are located at a registry entry you can do this as well: (Get-ItemProperty -literalpath .).'(default)'Dangle
This comes up in intellisense in the PowerShell ISE, if you assign it to a variable and run it, which is nice if this is one of a hundred things that you find yourself forgetting.Diffusivity
R
9
  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

Representative answered 22/5, 2018 at 3:44 Comment(0)
P
4

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}}
Pancreas answered 23/9, 2019 at 19:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.