I need to write a Script to change the Value of the (Standard) Key located in the Registry under:
REGISTRY::HKEY_CLASSES_ROOT\http\shell\open\command
I just cant get anything to work, everything i tried gives me the same response.
The Closest i've been is probably the following Code (was searching for a Solution Online):
$keypath = 'REGISTRY::HKEY_CLASSES_ROOT\http\shell\open\command\'
(Get-ItemProperty -Path $keypath -Name '(Standard)').'(Standard)'
But all I get back from it is:
Property (Standard) does not exist at path HKEY_CLASSES_ROOT\http\shell\open\command.
even though it clearly does exists. I assume im doing something clearly wrong, I tried searching for a solution and all I found was the code above.
Any Ideas?
Whereas the .NET APIs represent the unnamed default value as the empty string (''
or ""
in PowerShell), PowerShell's registry provider uses '(default)'
(invariably; that is, this string is not localized according the Windows display language, whereas it is in Registry Editor, for instance):
$keypath = 'REGISTRY::HKEY_CLASSES_ROOT\http\shell\open\command\'
# GET the data of the unnamed default value.
# NOTE: Reports an *error* if the unnamed value doesn't exist.
Get-ItemPropertyValue -Path $keypath -Name '(default)'
# SET the data of the unnamed default value - REQUIRES ELEVATION
Set-ItemProperty -Path $keypath -Name '(default)' -Value 'new value'
Note:
Get-ItemPropertyValue
rather than Get-ItemProperty
is used in order to directly extract only the data from the targeted registry value.
.GetValue('')
solution below.While Set-ItemProperty
works fine for setting the unnamed-value data, as of PowerShell (Core) 7 v7.4.x, Remove-ItemProperty
unexpectedly does not recognize '(Default)'
- see GitHub issue #6243.
Modifying data in the HKEY_CLASSES_ROOT
registry hive usually requires elevation (running as admin).
Use of .NET APIs as an alternative:
For getting the data, you could alternatively use Get-Item
and call the .GetValue()
method on the resulting Microsoft.Win32.RegistryKey
instance as follows:
# GET the data of the unnamed default value.
# EQUIVALENT OF:
# Get-ItemPropertyValue -Path $keypath -Name '(default)'
# EXCEPT that $null is returned if the unnamed value doesn't exist.
(Get-Item $keypath).GetValue('')
However, for setting the data, using the complementary .SetValue()
method does NOT work, because the Microsoft.Win32.RegistryKey
instance returned by Get-Item
is read-only. Therefore, use of .SetValue()
requires use of .NET APIs only:
# SET the data of the unnamed default value - REQUIRES ELEVATION
# NOTE:
# * Do NOT use a leading '\' in the key path.
# * $true as the second argument makes the key writeable.
$regKey = [Microsoft.Win32.Registry]::ClassesRoot.OpenSubKey(
'http\shell\open\command',
$true
)
$regKey.SetValue('', 'new value')
$regKey.Dispose()