I am trying to make a powershell script that adds some registry keys. But (I think) I am failing on the * folder under HKCR being recognized as a wildcard The goal of the powershell is to provide me with an "Open with Notepad++" option in the right click context menu of Windows 11, preferably (but not necessary) only for .bat and .cmd files.
The first 3 keys are being processed fine, but as soon as the 4th key needs to be handled it seems like it is running forever, no output is being generated anymore and the script doesn't finish.
The line that I think is causing the issue is: 'HKCR:`*\shell\Open with Notepad++'
My original code didn't have the backtick before the asterix, but without, with single and with double backtick before the asterix, the issue remains the same.
Thank you for your help!
# Check if 'HKEY_CLASSES_ROOT' path has been set
If (Get-PSDrive |
Where {
($PSitem.Name -Match 'HKCR') -and
($PSitem.Root -Match 'HKEY_CLASSES_ROOT')
}
)
{
}
Else {
New-PSDrive -PSProvider registry -Root "HKEY_CLASSES_ROOT" -Name "HKCR" >$Null 2>&1
}
# Define the registry values to add/update
$registryValues = @(
@{
Path = 'HKCR:\batfile\shell\Open with\command'
Name = '(default)'
Value = '{09799AFB-AD67-11d1-ABCD-00C04FC30936}'
},
@{
Path = 'HKCR:\batfile\shell\edit\command'
Name = '(default)'
Value = '"C:\Program Files (x86)\Notepad++\notepad++.exe %1"'
},
@{
Path = 'HKCR:\cmdfile\shell\edit\command'
Name = '(default)'
Value = '"C:\Program Files (x86)\Notepad++\notepad++.exe %1"'
},
@{
Path = 'HKCR:\`*\shell\Open with Notepad++'
Name = 'Icon'
Value = 'C:\Program Files (x86)\Notepad++\notepad++.exe'
},
@{
Path = 'HKCR:\`*\shell\Open with Notepad++\command'
Name = '(default)'
Value = '"C:\Program Files (x86)\Notepad++\notepad++.exe %1"'
}
)
# Function to create or update registry values
function Set-RegistryValue {
param(
[string]$Path,
[string]$Name,
[string]$Value
)
# Create the key if it does not exist
If (-NOT (Test-Path $Path)) {
New-Item -Path $Path -Force | Out-Null
}
# Now set the value
New-ItemProperty -Path $Path -Name $Name -Value $Value -PropertyType String -Force
}
# Add or update the registry values
foreach ($entry in $registryValues) {
Set-RegistryValue -Path $entry.Path -Name $entry.Name -Value $entry.Value
}