Google Chrome Universal Uninstaller

From psadt | Evergreen Application Management
Jump to navigation Jump to search

The Chrome web browser was the bane of my existence for an entire year.


While over 99% of deployments were successful, the less than 1% were the noisy minority, escalating to management who then forced us to look at why there were any failures at all. Exhaustive investigations found the nature of the installer is that you're not supposed to touch it via Transform (MST) file or anything else.

Put simply, it wants to self-update. Any attempt to suppress this process essentially breaks it. Many will be aware that there is an Update service which can be disabled. Many are unaware that there is a scheduled task to re-enable it for you (so thoughtful!)

Additionally, there are some registry keys which must be deleted if your uninstall or upgrade attempt is to succeed. Otherwise the MSI tends to fail with a 1603 error. I also noticed while wrestling with this application that trying to uninstall it with a PowerShell script also tends to cause 1603 fails, which admittedly may have been environmental for that client, but I didn't have the time to confirm either way.

All of this is meant to convince us that it just isn’t worth it, and we should just accept the fact and hand over control of our update process to the vendor. While you may be prepared to live with this (I won’t judge), we still may need to remove the thing on occasion when troubleshooting.

Given my experience with 1603 errors in PowerShell, this uninstaller is written in VB script.


' This script performs the installation or uninstallation of an application(s).
' Created 30/07/2019 |
' Variables
Set FSO = CreateObject("Scripting.FileSystemObject")
Set Shell = CreateObject("Wscript.Shell")
Set objWMI = GetObject("winmgmts:\.\root\cimv2")
Set EnvVar = Shell.Environment("PROCESS")
Set objReg = GetObject("winmgmts:\.\root\default:StdRegProv")
Set objNetwork = CreateObject("WScript.Network")
Const ForAppending = 8
Const forReading = 1
Const ForWriting = 2
Const HKCR = &H80000000
Const HKCU = &H80000001
Const HKLM = &H80000002
Const HKU = &H80000003
Const HKCC = &H80000005

Dim strProcess,Q,LogFile,WorkDir,strProgramData
WorkDir = Split(WScript.ScriptFullName,WSCRIPT.ScriptName)(0)
Q = Chr(034)
strProgramData = Shell.ExpandEnvironmentStrings("%ProgramData%")
strLogName = strProgramData & "\Logs\Google Chrome Universal Uninstaller.log"

' Start logging
If NOT FSO.FileExists(strLogName) Then CreateLogFile strLogName
LogInfo "========================= Google Chrome Universal Uninstaller ========================="
LogInfo "Machine Name: " & objNetwork.ComputerName
LogInfo "Uninstalled by: " & objNetwork.UserName
LogInfo "Uninstalled from: " & WorkDir

' Perform registry cleanup
strKeyPath = "SOFTWARE\Google\Update"
objReg.DeleteKey HKLM,strKeyPath
strKeyPath = "SOFTWARE\WOW6432Node\Google\Update"
objReg.DeleteKey HKLM,strKeyPath
strKeyPath = "SOFTWARE\Policies\Google\Update"
objReg.DeleteKey HKLM,strKeyPath
strKeyPath = "SOFTWARE\WOW6432Node\Policies\Google\Update"
objReg.DeleteKey HKLM,strKeyPath

' Uninstall Chrome versions
Shell.Run "TASKKILL /F /IM chrome.exe", , True
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
objReg.EnumKey HKLM, strKeyPath, arrSubKeys
sMatch = "Google Chrome"
For Each objSubKey In arrSubKeys
    On error resume next
        sDisplayName = Shell.Regread("HKLM\" & strKeyPath & "\" & objSubKey & "\DisplayName")
        sDisplayVersion = Shell.Regread("HKLM\" & strKeyPath & "\" & objSubKey & "\DisplayVersion")
    If err.number = 0 then 
        If InStr(sDisplayName, sMatch) > 0 then
            On Error Resume Next
            LogInfo "Uninstalling Google Chrome " & sDisplayVersion
            ExitCode = Shell.Run("MsiExec.exe /X" & objSubkey & " /quiet /norestart" & Q,0,1)
            If ExitCode = 0 Then LogInfo " Uninstall exit code: " & ExitCode & ". The operation completed successfully."
            If ExitCode = 1603 Then LogInfo " Uninstall exit code: " & ExitCode & ". Fatal error during installation."
            If ExitCode = 1605 Then LogInfo " Uninstall exit code: " & ExitCode & ". This action is only valid for products that are currently installed."
            Wscript.Sleep 10000
        End If
    End If


' Functions
Function myTime()
    myTime = DatePart("d",Now())&"/"& DatePart("m",Now())&"/"& DatePart("yyyy",Now())&" "&Time()
End Function

Function CreateLogFile(sLogfile)
    Set objLogFile = FSO.OpenTextFile(strLogName, ForWriting, True)
    objLogFile.WriteLine ""
    objLogFile.WriteLine myTime & " : " & WScript.ScriptName & " started."
    objLogFile.WriteLine ""
    Set objLogFile = Nothing
    logFileCreated = True
End Function

Function LogInfo(sMsg)
    If sMsg <> "" Then
        text = myTime & " : " & sMsg
        text = ""
    End If

    '*** Open the log file now
    Set objLogFile = FSO.OpenTextFile(strLogName, ForAppending, True)
        '*** Write the text required to the file
        objLogFile.WriteLine text

    '*** Close the log file and clear it from memory
    Set objLogFile = Nothing
End Function