From: Ardis Lu Date: Fri, 13 Sep 2024 02:55:01 +0000 (-0700) Subject: Gracefully abort if browser is not installed X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=98c6332a5b8e53b4ac0760b647850a77a7503fbc;p=ArdisUtilities Gracefully abort if browser is not installed --- diff --git a/ArdisUtilities/ArdisUtilities.psm1 b/ArdisUtilities/ArdisUtilities.psm1 index 3d08e8b..e9b8a73 100644 --- a/ArdisUtilities/ArdisUtilities.psm1 +++ b/ArdisUtilities/ArdisUtilities.psm1 @@ -1008,7 +1008,7 @@ function Open-TemporaryBrowser { # 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 {} } @@ -1016,7 +1016,7 @@ function Open-TemporaryBrowser { 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 {} } @@ -1024,7 +1024,7 @@ function Open-TemporaryBrowser { 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 {} } @@ -1037,6 +1037,11 @@ function Open-TemporaryBrowser { '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)