Finished basic implementation of uninstalling legacy versions.

This commit is contained in:
Sparer, David
2016-05-26 15:37:12 -06:00
parent daff0de0bd
commit fe9aa59690
6 changed files with 123 additions and 2 deletions

View File

@@ -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;
}
}
}

View File

@@ -33,7 +33,8 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<StartupObject />
<StartupObject>
</StartupObject>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
@@ -46,6 +47,7 @@
<Compile Include="CustomActions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="InstalledWindowsUpdateGatherer.cs" />
<Compile Include="UninstallNSISVersions.cs" />
<Content Include="CustomAction.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

View File

@@ -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)
{ }
}
}
}

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<?include $(sys.CURRENTDIR)Includes\Config.wxi?>
<Fragment>
<CustomAction Id="CheckIfLegacyVersionInstalled" Return="check" Execute="immediate" BinaryKey="CustomActions.CA.dll" DllEntry="IsLegacyVersionInstalled" />
</Fragment>
<Fragment>
<CustomAction Id="UninstallLegacyVersion" Return="check" Execute="immediate" BinaryKey="CustomActions.CA.dll" DllEntry="UninstallLegacyVersion" />
</Fragment>
</Wix>

View File

@@ -27,6 +27,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="CustomActions\CheckForInstalledWindowsUpdates.wxs" />
<Compile Include="CustomActions\UninstallLegacyVersions.wxs" />
<Compile Include="Fragments\FilesFragment.wxs" />
<Compile Include="Fragments\DirectoriesFragment.wxs" />
<Compile Include="Fragments\MainExeFragment.wxs" />

View File

@@ -17,13 +17,17 @@
<RegistrySearch Id='mRemoteNGRegistry' Type='raw' Root='HKLM' Key='Software\mRemoteNG' Name='InstallDir' />
</Property>
<Property Id='REQUIREDDOTNETFRAMEWORKVERSION' Value='$(var.RequiredDotNetFrameworkVersion)' />
<Property Id='LEGACYVERSIONINSTALLED' Value='0' />
<PropertyRef Id="NETFRAMEWORK40FULL" />
<PropertyRef Id="WIX_IS_NETFRAMEWORK_40_OR_LATER_INSTALLED" />
<Icon Id="mRemoteNG.ico" SourceFile="Resources\mRemoteNG.ico" />
<InstallUISequence>
<Custom Action="SetRDP80KBValue" After="AppSearch" />
<Custom Action="CheckIfRDP80Installed" After="SetRDP80KBValue">NOT Installed AND (VersionNT = 601 OR VersionNT64 = 601)</Custom>
<Custom Action="CheckIfRDP80Installed" After="SetRDP80KBValue">(NOT Installed) AND (VersionNT = 601 OR VersionNT64 = 601)</Custom>
<LaunchConditions After="SetWIX_IS_NETFRAMEWORK_40_OR_LATER_INSTALLED" />
<Custom Action="CheckIfLegacyVersionInstalled" After="LaunchConditions" />
<Custom Action="UninstallLegacyVersion" After="CheckIfLegacyVersionInstalled">(NOT Installed) AND (LEGACYVERSIONINSTALLED = 1)</Custom>
</InstallUISequence>