Uninstall Google Chrome (All Versions) - Windows Server

Hi - I’m a action script novice and need help finding the problem with this:

waithidden msiexec.exe /X { name of keys whose( (exists values “DisplayName” whose(it as string as lowercase starts with “Google Chrome” as lowercase) of it) AND (exists values whose(it as string as lowercase starts with “msiexec”) of it) ) of keys “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall” of ( x64 registries; x32 registries ) } /qn

From the client log:

Command failed (Relevance substitution failed) waithidden msiexec.exe /X { name of keys whose( (exists values “DisplayName” whose(it as string as lowercase starts with “Google Chrome” as lowercase) of it) AND (exists values whose(it as string as lowercase starts with “msiexec”) of it) ) of keys “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall” of ( x64 registries; x32 registries ) } /qn (action:563209)

tl;dr - trying to uninstall Google Chrime (any/all versions). If you have any other suggestions I’d be in your debt.

Google Chrome is not always installed and registered in this way so you can’t rely 100% on using this approach, however here is the actionscript that will follow your original design:

if {number of keys whose (value "DisplayName" of it as string = "Google Chrome" and value "UninstallString" of it as string  as lowercase starts with "msiexec.exe") of keys "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" of (x64 registries; x32 registries) = 1}
    waithidden "C:\Windows\System32\msiexec.exe" /X{name of keys whose (value "DisplayName" of it as string = "Google Chrome" and value "UninstallString" of it as string  as lowercase starts with "msiexec.exe") of keys "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" of (x64 registries; x32 registries)} /qn
endif

The quote marks in your pasted code are also the incorrect ones (but I was assuming those were just translated by Windows as you were typing the forum message in). The error you were getting was most likely due to the singular expectation (i.e. “name of”) failing because either no keys were present or multiple keys being present. The above actionscript accounts for this by first checking for the existence of exactly 1 found key before constructing and executing the uninstall string.

Alternatively, if there were multiple possible installed versions (this shouldn’t happen for Google Chrome when using the system-wide installer), you would need to construct a batch file containing all of the removal statements identified (due to there not being support for looping in relevance/actionscript) then calling that constructed batch file. This also works if there were only a single install.

if {number of keys whose (value "DisplayName" of it as string = "Google Chrome" and value "UninstallString" of it as string  as lowercase starts with "msiexec.exe") of keys "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" of (x64 registries; x32 registries) > 0}
    delete __appendfile
    appendfile {concatenation "%0d%0a" of ("%22C:\Windows\System32\msiexec.exe%22 /X" & it & " /qn") of unique values of names of keys whose (value "DisplayName" of it as string = "Google Chrome" and value "UninstallString" of it as string  as lowercase starts with "msiexec.exe") of keys "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" of (x64 registries; x32 registries)}
    move __appendfile remove_chrome.bat
    waithidden remove_chrome.bat
endif

I added the “unique names” to the relevance in the event that there were identical 32-bit and 64-bit registry key GUID names found.

You might want to also extract the application GUID out of the UninstallString directly instead of relying upon the registry key name to be the same value (as this is not always the case). Here is one way to do this:

if {number of keys whose (value "DisplayName" of it as string = "Google Chrome" and value "UninstallString" of it as string  as lowercase starts with "msiexec.exe") of keys "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" of (x64 registries; x32 registries) = 1}
   waithidden "C:\Windows\System32\msiexec.exe" /X{(("%7b" & preceding text of first "%7d" of following text of first "%7b" of (value "UninstallString" of it as string) & "%7d") | name of it) of
keys whose (value "DisplayName" of it as string = "Google Chrome" and value "UninstallString" of it as string as lowercase starts with "msiexec.exe") of keys "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" of (x64 registries; x32 registries)} /qn
endif

Hope this helps you out!

2 Likes

I’m looking for something like this but reading other forum posts, it seems like Chrome being installed in the user profile causes complications because that user probably won’t be logged onto a server (unlike a workstation).

Does this actionscript account for that or is it only looking if it is installed for all users (and presumably installed to ‘Program File’ ?

1 Like