# Wrapping in try/catch is required because -ErrorAction is ignored for terminating errors
foreach ($key in @('Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\Brave\shell\open\command', 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\brave.exe')) {
try {
- $bravePath ??= Get-ItemPropertyValue -LiteralPath $key -Name '(default)'
+ $bravePath ??= Get-ItemPropertyValue -LiteralPath $key -Name '(default)' -ErrorAction SilentlyContinue
}
catch {}
}
foreach ($key in @('Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\Google Chrome\shell\open\command', 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe')) {
try {
- $chromePath ??= Get-ItemPropertyValue -LiteralPath $key -Name '(default)'
+ $chromePath ??= Get-ItemPropertyValue -LiteralPath $key -Name '(default)' -ErrorAction SilentlyContinue
}
catch {}
}
foreach ($key in @('Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\Microsoft Edge\shell\open\command', 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\msedge.exe')) {
try {
- $edgePath ??= Get-ItemPropertyValue -LiteralPath $key -Name '(default)'
+ $edgePath ??= Get-ItemPropertyValue -LiteralPath $key -Name '(default)' -ErrorAction SilentlyContinue
}
catch {}
}
'Chrome' { $execPath = $chromePath }
'Edge' { $execPath = $edgePath }
}
+ $execPath = $execPath.Replace("`"", '') # Registry values have leading and trailing quote literals in the string
+
+ if (-not(Test-Path -LiteralPath $execPath -PathType Leaf)) {
+ throw "Could not find browser `"$Browser`" at path `"$execPath`", aborting."
+ }
$temp = Join-Path $Env:Temp $(New-Guid)