1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
7 This script reads the uninstall command from registry, calls it, and verifies
8 the output status code.
18 parser = optparse.OptionParser(description='Uninstall Chrome.')
19 parser.add_option('--system-level', action='store_true', dest='system_level',
20 default=False, help='Uninstall Chrome at system level.')
21 parser.add_option('--chrome-long-name', default='Google Chrome',
22 help='Google Chrome or Chromium)')
23 parser.add_option('--interactive', action='store_true', dest='interactive',
24 default=False, help='Ask before uninstalling Chrome.')
25 parser.add_option('--no-error-if-absent', action='store_true',
26 dest='no_error_if_absent', default=False,
27 help='No error if the registry key for uninstalling Chrome '
29 options, _ = parser.parse_args()
31 # TODO(sukolsak): Add support for uninstalling MSI-based Chrome installs when
32 # we support testing MSIs.
33 if options.system_level:
34 root_key = _winreg.HKEY_LOCAL_MACHINE
36 root_key = _winreg.HKEY_CURRENT_USER
37 sub_key = ('SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\%s' %
38 options.chrome_long_name)
39 # Query the key. It will throw a WindowsError if the key doesn't exist.
41 key = _winreg.OpenKey(root_key, sub_key, 0, _winreg.KEY_QUERY_VALUE)
43 if options.no_error_if_absent:
45 raise KeyError('Registry key %s\\%s is missing' % (
46 'HKEY_LOCAL_MACHINE' if options.system_level else 'HKEY_CURRENT_USER',
48 if options.interactive:
49 prompt = ('Warning: This will uninstall %s at %s. Do you want to continue? '
50 '(y/N) ' % (options.chrome_long_name,
52 options.system_level else 'user-level'))
53 if raw_input(prompt).strip() != 'y':
54 print >> sys.stderr, 'User aborted'
56 uninstall_string, _ = _winreg.QueryValueEx(key, 'UninstallString')
57 exit_status = subprocess.call(uninstall_string + ' --force-uninstall',
59 # The exit status for successful uninstallation of Chrome is 19 (see
60 # chrome/installer/util/util_constants.h).
62 raise Exception('Could not uninstall Chrome. The installer exited with '
63 'status %d.' % exit_status)
67 if __name__ == '__main__':