From fe9aa596902aaba1b6ab50a7563ed0d8cb59860f Mon Sep 17 00:00:00 2001 From: "Sparer, David" Date: Thu, 26 May 2016 15:37:12 -0600 Subject: [PATCH] Finished basic implementation of uninstalling legacy versions. --- .../CustomActions/CustomActions.cs | 29 +++++++ .../CustomActions/CustomActions.csproj | 4 +- .../CustomActions/UninstallNSISVersions.cs | 75 +++++++++++++++++++ .../CustomActions/UninstallLegacyVersions.wxs | 10 +++ .../Installer/Installer.wixproj | 1 + Installer Projects/Installer/mRemoteNGV1.wxs | 6 +- 6 files changed, 123 insertions(+), 2 deletions(-) create mode 100644 Installer Projects/CustomActions/UninstallNSISVersions.cs create mode 100644 Installer Projects/Installer/CustomActions/UninstallLegacyVersions.wxs diff --git a/Installer Projects/CustomActions/CustomActions.cs b/Installer Projects/CustomActions/CustomActions.cs index 2ecdf6a3..8d8c5f71 100644 --- a/Installer Projects/CustomActions/CustomActions.cs +++ b/Installer Projects/CustomActions/CustomActions.cs @@ -27,5 +27,34 @@ namespace CustomActions session.Log("End IsKBInstalled"); return ActionResult.Success; } + + [CustomAction] + public static ActionResult UninstallLegacyVersion(Session session) + { + session.Log("Begin UninstallLegacyVersion"); + UninstallNSISVersions uninstaller = new UninstallNSISVersions(); + string uninstallString = uninstaller.GetLegacyUninstallString(); + uninstaller.UninstallLegacyVersion(); + session.Log("End UninstallLegacyVersion"); + return ActionResult.Success; + } + + [CustomAction] + public static ActionResult IsLegacyVersionInstalled(Session session) + { + session.Log("Begin IsLegacyVersionInstalled"); + UninstallNSISVersions uninstaller = new UninstallNSISVersions(); + if (uninstaller.IsLegacymRemoteNGInstalled()) + { + session["LEGACYVERSIONINSTALLED"] = "1"; + } + else + { + session["LEGACYVERSIONINSTALLED"] = "0"; + } + + session.Log("End IsLegacyVersionInstalled"); + return ActionResult.Success; + } } } \ No newline at end of file diff --git a/Installer Projects/CustomActions/CustomActions.csproj b/Installer Projects/CustomActions/CustomActions.csproj index c24e2fce..ce227710 100644 --- a/Installer Projects/CustomActions/CustomActions.csproj +++ b/Installer Projects/CustomActions/CustomActions.csproj @@ -33,7 +33,8 @@ 4 - + + @@ -46,6 +47,7 @@ + diff --git a/Installer Projects/CustomActions/UninstallNSISVersions.cs b/Installer Projects/CustomActions/UninstallNSISVersions.cs new file mode 100644 index 00000000..17866ade --- /dev/null +++ b/Installer Projects/CustomActions/UninstallNSISVersions.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Microsoft.Win32; +using System.Diagnostics; +using System.IO; + +namespace CustomActions +{ + public class UninstallNSISVersions + { + private const string REGISTRY_PATH = "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\mRemoteNG"; + private const string REGISTRY_PATH_Wow6432 = "Software\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\mRemoteNG"; + private RegistryKey _activeRegistryPath; + + + public UninstallNSISVersions() + { + GetLegacymRemoteNGRegistryKeyPath(); + } + + public void UninstallLegacyVersion() + { + if (!IsLegacymRemoteNGInstalled()) + return; + string uninstallString = GetLegacyUninstallString(); + ProcessStartInfo processStartInfo = new ProcessStartInfo(uninstallString); + processStartInfo.UseShellExecute = true; + processStartInfo.Arguments = string.Format("_?={0}", uninstallString.Replace("Uninstall.exe", "").Replace(@"""", "")); + Process uninstallProcess = Process.Start(processStartInfo); + while (uninstallProcess.HasExited == false) + { + Debug.WriteLine("Waiting for uninstaller to exit"); + } + } + + public bool IsLegacymRemoteNGInstalled() + { + return (_activeRegistryPath != null); + } + + public string GetLegacyUninstallString() + { + if (IsLegacymRemoteNGInstalled()) + return _activeRegistryPath.GetValue("UninstallString").ToString(); + return ""; + } + + private void GetLegacymRemoteNGRegistryKeyPath() + { + GetUninstallKeyPath(); + GetUninstallKeyPath6432(); + } + + private void GetUninstallKeyPath() + { + try + { + _activeRegistryPath = Registry.LocalMachine.OpenSubKey(REGISTRY_PATH); + } + catch (Exception ex) + { } + } + + private void GetUninstallKeyPath6432() + { + try + { + _activeRegistryPath = Registry.LocalMachine.OpenSubKey(REGISTRY_PATH_Wow6432); + } + catch (Exception ex) + { } + } + } +} \ No newline at end of file diff --git a/Installer Projects/Installer/CustomActions/UninstallLegacyVersions.wxs b/Installer Projects/Installer/CustomActions/UninstallLegacyVersions.wxs new file mode 100644 index 00000000..65dc0d17 --- /dev/null +++ b/Installer Projects/Installer/CustomActions/UninstallLegacyVersions.wxs @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/Installer Projects/Installer/Installer.wixproj b/Installer Projects/Installer/Installer.wixproj index 8f3a1f9f..e5c926bd 100644 --- a/Installer Projects/Installer/Installer.wixproj +++ b/Installer Projects/Installer/Installer.wixproj @@ -27,6 +27,7 @@ + diff --git a/Installer Projects/Installer/mRemoteNGV1.wxs b/Installer Projects/Installer/mRemoteNGV1.wxs index 991c1c1e..7889f333 100644 --- a/Installer Projects/Installer/mRemoteNGV1.wxs +++ b/Installer Projects/Installer/mRemoteNGV1.wxs @@ -17,13 +17,17 @@ + - NOT Installed AND (VersionNT = 601 OR VersionNT64 = 601) + (NOT Installed) AND (VersionNT = 601 OR VersionNT64 = 601) + + + (NOT Installed) AND (LEGACYVERSIONINSTALLED = 1)