1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
|
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// This file defines the methods useful for uninstalling Chrome.
#include "chrome/installer/setup/uninstall.h"
#include <atlbase.h>
#include <windows.h>
#include <msi.h>
#include "base/file_util.h"
#include "base/path_service.h"
#include "base/registry.h"
#include "base/scoped_ptr.h"
#include "base/string_util.h"
#include "base/win_util.h"
#include "base/wmi_util.h"
#include "chrome/app/result_codes.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/installer/setup/setup.h"
#include "chrome/installer/setup/setup_constants.h"
#include "chrome/installer/util/browser_distribution.h"
#include "chrome/installer/util/helper.h"
#include "chrome/installer/util/install_util.h"
#include "chrome/installer/util/l10n_string_util.h"
#include "chrome/installer/util/logging_installer.h"
#include "chrome/installer/util/google_update_constants.h"
#include "chrome/installer/util/google_update_settings.h"
#include "chrome/installer/util/shell_util.h"
#include "chrome/installer/util/util_constants.h"
#include "chrome/installer/util/version.h"
#include "installer_util_strings.h"
namespace {
// This method deletes Chrome shortcut folder from Windows Start menu. It
// checks system_uninstall to see if the shortcut is in all users start menu
// or current user start menu.
void DeleteChromeShortcut(bool system_uninstall) {
std::wstring shortcut_path;
if (system_uninstall) {
PathService::Get(base::DIR_COMMON_START_MENU, &shortcut_path);
} else {
PathService::Get(base::DIR_START_MENU, &shortcut_path);
}
if (shortcut_path.empty()) {
LOG(ERROR) << "Failed to get location for shortcut.";
} else {
BrowserDistribution* dist = BrowserDistribution::GetDistribution();
file_util::AppendToPath(&shortcut_path, dist->GetApplicationName());
LOG(INFO) << "Deleting shortcut " << shortcut_path;
if (!file_util::Delete(shortcut_path, true))
LOG(ERROR) << "Failed to delete folder: " << shortcut_path;
}
}
// This method tries to delete a registry key and logs an error message
// in case of failure. It returns true if deletion is successful,
// otherwise false.
bool DeleteRegistryKey(RegKey& key, const std::wstring& key_path) {
LOG(INFO) << "Deleting registry key " << key_path;
if (!key.DeleteKey(key_path.c_str())) {
LOG(ERROR) << "Failed to delete registry key: " << key_path;
return false;
}
return true;
}
// This method tries to delete a registry value and logs an error message
// in case of failure. It returns true if deletion is successful,
// otherwise false.
bool DeleteRegistryValue(HKEY reg_root, const std::wstring& key_path,
const std::wstring& value_name) {
RegKey key(reg_root, key_path.c_str(), KEY_ALL_ACCESS);
LOG(INFO) << "Deleting registry value " << value_name;
if (!key.DeleteValue(value_name.c_str())) {
LOG(ERROR) << "Failed to delete registry value: " << value_name;
return false;
}
return true;
}
// This method checks if Chrome is currently running or if the user has
// cancelled the uninstall operation by clicking Cancel on the confirmation
// box that Chrome pops up.
installer_util::InstallStatus IsChromeActiveOrUserCancelled(
bool system_uninstall) {
static const std::wstring kCmdLineOptions(L" --uninstall");
int32 exit_code = ResultCodes::NORMAL_EXIT;
// Here we want to save user from frustration (in case of Chrome crashes)
// and continue with the uninstallation as long as chrome.exe process exit
// code is NOT one of the following:
// - UNINSTALL_CHROME_ALIVE - chrome.exe is currently running
// - UNINSTALL_USER_CANCEL - User cancelled uninstallation
// - HUNG - chrome.exe was killed by HuntForZombieProcesses() (until we can
// give this method some brains and not kill chrome.exe launched
// by us, we will not uninstall if we get this return code).
LOG(INFO) << "Launching Chrome to do uninstall tasks.";
if (installer::LaunchChromeAndWaitForResult(system_uninstall,
kCmdLineOptions,
&exit_code)) {
LOG(INFO) << "chrome.exe launched for uninstall confirmation returned: "
<< exit_code;
if ((exit_code == ResultCodes::UNINSTALL_CHROME_ALIVE) ||
(exit_code == ResultCodes::UNINSTALL_USER_CANCEL) ||
(exit_code == ResultCodes::HUNG))
return installer_util::UNINSTALL_CANCELLED;
} else {
LOG(ERROR) << "Failed to launch chrome.exe for uninstall confirmation.";
}
return installer_util::UNINSTALL_CONFIRMED;
}
} // namespace
installer_util::InstallStatus installer_setup::UninstallChrome(
const std::wstring& exe_path, bool system_uninstall,
const installer::Version& installed_version, bool remove_all) {
installer_util::InstallStatus status =
IsChromeActiveOrUserCancelled(system_uninstall);
if (status != installer_util::UNINSTALL_CONFIRMED)
return status;
BrowserDistribution* dist = BrowserDistribution::GetDistribution();
dist->DoPreUninstallOperations();
#if defined(GOOGLE_CHROME_BUILD)
// TODO(rahulk): This should be done by DoPreUninstallOperations call above
wchar_t product[39]; // GUID + '\0'
MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL); // Don't show any UI to user.
for (int i = 0; MsiEnumRelatedProducts(google_update::kGearsUpgradeCode, 0, i,
product) != ERROR_NO_MORE_ITEMS; ++i) {
LOG(INFO) << "Uninstalling Gears - " << product;
unsigned int ret = MsiConfigureProduct(product, INSTALLLEVEL_MAXIMUM,
INSTALLSTATE_ABSENT);
if (ret != ERROR_SUCCESS)
LOG(ERROR) << "Failed to uninstall Gears " << product << ": " << ret;
}
#endif
// Chrome is not in use so lets uninstall Chrome by deleting various files
// and registry entries. Here we will just make best effort and keep going
// in case of errors.
// First delete shortcut from Start->Programs.
DeleteChromeShortcut(system_uninstall);
// Delete the registry keys (Uninstall key and Version key).
HKEY reg_root = system_uninstall ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
RegKey key(reg_root, L"", KEY_ALL_ACCESS);
DeleteRegistryKey(key, dist->GetUninstallRegPath());
DeleteRegistryKey(key, dist->GetVersionKey());
// Delete Software\Classes\ChromeHTML,
// Software\Clients\StartMenuInternet\chrome.exe and
// Software\RegisteredApplications\Chrome
std::wstring html_prog_id(ShellUtil::kRegClasses);
file_util::AppendToPath(&html_prog_id, ShellUtil::kChromeHTMLProgId);
DeleteRegistryKey(key, html_prog_id);
std::wstring set_access_key(ShellUtil::kRegStartMenuInternet);
file_util::AppendToPath(&set_access_key, installer_util::kChromeExe);
DeleteRegistryKey(key, set_access_key);
DeleteRegistryValue(reg_root, ShellUtil::kRegRegisteredApplications,
dist->GetApplicationName());
key.Close();
// Delete shared registry keys as well (these require admin rights) if
// remove_all option is specified.
if (remove_all) {
RegKey hklm_key(HKEY_LOCAL_MACHINE, L"", KEY_ALL_ACCESS);
DeleteRegistryKey(hklm_key, set_access_key);
DeleteRegistryKey(hklm_key, html_prog_id);
DeleteRegistryValue(HKEY_LOCAL_MACHINE,
ShellUtil::kRegRegisteredApplications,
dist->GetApplicationName());
// Delete media player registry key that exists only in HKLM.
std::wstring reg_path(installer::kMediaPlayerRegPath);
file_util::AppendToPath(®_path, installer_util::kChromeExe);
DeleteRegistryKey(hklm_key, reg_path);
hklm_key.Close();
}
// Finally delete all the files from Chrome folder after moving setup.exe
// to a temp location.
std::wstring install_path(installer::GetChromeInstallPath(system_uninstall));
if (install_path.empty()) {
LOG(ERROR) << "Could not get installation destination path.";
// Nothing else we could do for uninstall, so we return.
return installer_util::UNINSTALL_FAILED;
} else {
LOG(INFO) << "install destination path: " << install_path;
}
std::wstring setup_exe(installer::GetInstallerPathUnderChrome(
install_path, installed_version.GetString()));
file_util::AppendToPath(&setup_exe, file_util::GetFilenameFromPath(exe_path));
std::wstring temp_file;
file_util::CreateTemporaryFileName(&temp_file);
file_util::Move(setup_exe, temp_file);
LOG(INFO) << "Deleting install path " << install_path;
if (!file_util::Delete(install_path, true))
LOG(ERROR) << "Failed to delete folder: " << install_path;
LOG(INFO) << "Uninstallation complete. Launching Uninstall survey.";
dist->DoPostUninstallOperations(installed_version);
return installer_util::UNINSTALL_SUCCESSFUL;
}
|