summaryrefslogtreecommitdiffstats
path: root/chrome/installer
diff options
context:
space:
mode:
authorkuchhal@chromium.org <kuchhal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-21 16:25:24 +0000
committerkuchhal@chromium.org <kuchhal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-21 16:25:24 +0000
commit2205b65d494a2188d7c480113a0f71fbcca27a67 (patch)
treefc4f3130c5c1cd258139911d7ce6bdd337a3885e /chrome/installer
parent36bbf7a7721021c992757d60a68a73d7751c8509 (diff)
downloadchromium_src-2205b65d494a2188d7c480113a0f71fbcca27a67.zip
chromium_src-2205b65d494a2188d7c480113a0f71fbcca27a67.tar.gz
chromium_src-2205b65d494a2188d7c480113a0f71fbcca27a67.tar.bz2
During uninstall on Vista try to elevate if registry entries from HKLM need to be deleted.
BUG=7178 Review URL: http://codereview.chromium.org/82003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14106 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/installer')
-rw-r--r--chrome/installer/setup/main.cc22
-rw-r--r--chrome/installer/util/shell_util.cc32
-rw-r--r--chrome/installer/util/shell_util.h4
3 files changed, 57 insertions, 1 deletions
diff --git a/chrome/installer/setup/main.cc b/chrome/installer/setup/main.cc
index 98b2191..4731b2f 100644
--- a/chrome/installer/setup/main.cc
+++ b/chrome/installer/setup/main.cc
@@ -454,6 +454,7 @@ installer_util::InstallStatus InstallChrome(const CommandLine& cmd_line,
}
installer_util::InstallStatus UninstallChrome(const CommandLine& cmd_line,
+ const wchar_t* cmd_params,
const installer::Version* version,
bool system_install) {
LOG(INFO) << "Uninstalling Chome";
@@ -468,6 +469,26 @@ installer_util::InstallStatus UninstallChrome(const CommandLine& cmd_line,
bool remove_all = !cmd_line.HasSwitch(
installer_util::switches::kDoNotRemoveSharedItems);
bool force = cmd_line.HasSwitch(installer_util::switches::kForceUninstall);
+
+ // Check if we need admin rights to cleanup HKLM. Try to elevate - if it works
+ // exit from this process, if not just continue uninstalling in the current
+ // process itself.
+ if (remove_all &&
+ ShellUtil::AdminNeededForRegistryCleanup() &&
+ !IsUserAnAdmin() &&
+ (win_util::GetWinVersion() >= win_util::WINVERSION_VISTA) &&
+ !cmd_line.HasSwitch(installer_util::switches::kRunAsAdmin)) {
+ std::wstring exe = cmd_line.program();
+ std::wstring params(cmd_params);
+ // Append --run-as-admin flag to let the new instance of setup.exe know
+ // that we already tried to launch ourselves as admin.
+ params.append(L" --");
+ params.append(installer_util::switches::kRunAsAdmin);
+ DWORD exit_code = installer_util::UNKNOWN_STATUS;
+ if (InstallUtil::ExecuteExeAsAdmin(exe, params, &exit_code))
+ return static_cast<installer_util::InstallStatus>(exit_code);
+ }
+
return installer_setup::UninstallChrome(cmd_line.program(), system_install,
*version, remove_all, force);
}
@@ -595,6 +616,7 @@ int WINAPI wWinMain(HINSTANCE instance, HINSTANCE prev_instance,
// If --uninstall option is given, uninstall chrome
if (parsed_command_line.HasSwitch(installer_util::switches::kUninstall)) {
install_status = UninstallChrome(parsed_command_line,
+ command_line,
installed_version.get(),
system_install);
// If --uninstall option is not specified, we assume it is install case.
diff --git a/chrome/installer/util/shell_util.cc b/chrome/installer/util/shell_util.cc
index 2e5e9c5..99fd0a6 100644
--- a/chrome/installer/util/shell_util.cc
+++ b/chrome/installer/util/shell_util.cc
@@ -152,7 +152,8 @@ class RegistryEntry {
}
}
- // Check if the current registry entry exists in HKLM registry.
+ // Checks if the current registry entry exists in HKLM registry and the value
+ // is same.
bool ExistsInHKLM() {
RegKey key(HKEY_LOCAL_MACHINE, _key_path.c_str());
bool found = false;
@@ -169,6 +170,22 @@ class RegistryEntry {
return found;
}
+ // Checks if the current registry entry exists in HKLM registry
+ // (only the name).
+ bool NameExistsInHKLM() {
+ RegKey key(HKEY_LOCAL_MACHINE, _key_path.c_str());
+ bool found = false;
+ if (_is_string) {
+ std::wstring read_value;
+ found = key.ReadValue(_name.c_str(), &read_value);
+ } else {
+ DWORD read_value;
+ found = key.ReadValueDW(_name.c_str(), &read_value);
+ }
+ key.Close();
+ return found;
+ }
+
private:
// Create a object that represent default value of a key
RegistryEntry(const std::wstring& key_path, const std::wstring& value) :
@@ -413,6 +430,19 @@ ShellUtil::RegisterStatus ShellUtil::AddChromeToSetAccessDefaults(
return ShellUtil::FAILURE;
}
+bool ShellUtil::AdminNeededForRegistryCleanup() {
+ bool cleanup_needed = false;
+ std::list<RegistryEntry*> entries = RegistryEntry::GetAllEntries(
+ installer_util::kChromeExe);
+ for (std::list<RegistryEntry*>::iterator itr = entries.begin();
+ itr != entries.end(); ++itr) {
+ if (!cleanup_needed && (*itr)->NameExistsInHKLM())
+ cleanup_needed = true;
+ delete (*itr);
+ }
+ return cleanup_needed;
+}
+
bool ShellUtil::GetChromeIcon(std::wstring& chrome_icon) {
if (chrome_icon.empty())
return false;
diff --git a/chrome/installer/util/shell_util.h b/chrome/installer/util/shell_util.h
index 6b2d3cc..b294f85 100644
--- a/chrome/installer/util/shell_util.h
+++ b/chrome/installer/util/shell_util.h
@@ -104,6 +104,10 @@ class ShellUtil {
static RegisterStatus AddChromeToSetAccessDefaults(
const std::wstring& chrome_exe, bool skip_if_not_admin);
+ // Checks if we need Admin rights for registry cleanup by checking if any
+ // entry exists in HKLM.
+ static bool AdminNeededForRegistryCleanup();
+
// Create Chrome shortcut on Desktop
// If shell_change is CURRENT_USER, the shortcut is created in the
// Desktop folder of current user's profile.