Parse install path of Google Chrome from registry

Viewed 651

I am trying to find the install path for Google Chrome from the registry in Powershell. I am able to do so, but I am trying to get only the install path returned, i.e C:\Program Files\Google\Chrome\Application\chrome.exe.

I am able to see the path from running GetItem HKLM:\SOFTWARE\Classes\ChromeHTML\shell\open\command, but I need to do further filtering to just return the path and nothing else. I am new to Powershell and I am struggling to find anything in the docs to help with this.

Current Output:

HIVE: HKEY_LOCAL_MACHINE:\SOFTWARE\Classes\ChromeHTML\shell\open

Name                    Property
----                    ----
command                 (default) : "C:\Program Files\Google\Chrome\Application\chrome.exe" -- 
                        single argument %1

Desired Output:

C:\Program Files\Google\Chrome\Application\chrome.exe

This is a standard Chrome install on Windows 10.

1 Answers

you do this:

$key = 'HKLM:\SOFTWARE\Classes\ChromeHTML\shell\open\command'
$res = (Get-ItemProperty -Path $key)."(default)" -replace " *--.*", ""

or another method , maybe more intuitive:

$res = (Get-Item -Path $key).GetValue("") -replace " *--.*", ""

result:

"C:\Program Files\Google\Chrome\Application\chrome.exe" 
Related