Specify registry view in InstallerService.

This commit is contained in:
Jared Goodwin 2020-02-22 17:47:05 -08:00 committed by Jared Goodwin
parent 053b16731a
commit 86e509d276
4 changed files with 50 additions and 22 deletions

View File

@ -97,7 +97,7 @@ namespace Remotely.Agent.Installer.Win.Services
ProcessWrapper.StartHidden("netsh", "advfirewall firewall delete rule name=\"Remotely ScreenCast\"").WaitForExit();
Registry.LocalMachine.DeleteSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Remotely", false);
GetRegistryBaseKey().DeleteSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Remotely", false);
return true;
@ -109,19 +109,6 @@ namespace Remotely.Agent.Installer.Win.Services
}
}
private async Task StopProcesses()
{
ProgressMessageChanged?.Invoke(this, "Stopping Remotely processes.");
var procs = Process.GetProcessesByName("Remotely_Agent").Concat(Process.GetProcessesByName("Remotely_ScreenCast"));
foreach (var proc in procs)
{
proc.Kill();
}
await Task.Delay(500);
}
private void AddFirewallRule()
{
var screenCastPath = Path.Combine(InstallPath, "ScreenCast", "Remotely_ScreenCast.exe");
@ -199,8 +186,9 @@ namespace Remotely.Agent.Installer.Win.Services
private void CreateUninstallKey()
{
var version = FileVersionInfo.GetVersionInfo(Path.Combine(InstallPath, "Remotely_Agent.exe"));
var baseKey = GetRegistryBaseKey();
var remotelyKey = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Remotely", true);
var remotelyKey = baseKey.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Remotely", true);
remotelyKey.SetValue("DisplayIcon", Path.Combine(InstallPath, "Remotely_Agent.exe"));
remotelyKey.SetValue("DisplayName", "Remotely");
remotelyKey.SetValue("DisplayVersion", version.FileVersion);
@ -211,6 +199,7 @@ namespace Remotely.Agent.Installer.Win.Services
remotelyKey.SetValue("UninstallString", Path.Combine(InstallPath, "Remotely_Installer.exe -uninstall"));
remotelyKey.SetValue("QuietUninstallString", Path.Combine(InstallPath, "Remotely_Installer.exe -uninstall -quiet"));
}
private async Task DownloadRemotelyAgent(string serverUrl)
{
var targetFile = Path.Combine(Path.GetTempPath(), $"Remotely-Agent.zip");
@ -294,15 +283,27 @@ namespace Remotely.Agent.Installer.Win.Services
return connectionInfo;
}
private RegistryKey GetRegistryBaseKey()
{
if (Environment.Is64BitOperatingSystem)
{
return RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
}
else
{
return RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);
}
}
private async Task InstallDesktpRuntimeIfNeeded()
{
Logger.Write("Checking for .NET Core runtime.");
var uninstallKeys = new List<RegistryKey>();
var runtimeInstalled = false;
foreach (var subkeyName in Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\", false).GetSubKeyNames())
foreach (var subkeyName in GetRegistryBaseKey().OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\", false).GetSubKeyNames())
{
var subkey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\" + subkeyName, false);
var subkey = GetRegistryBaseKey().OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" + subkeyName, false);
if (subkey?.GetValue("DisplayName")?.ToString()?.Contains("Microsoft Windows Desktop Runtime - 3.1.2") == true)
{
runtimeInstalled = true;
@ -391,6 +392,19 @@ namespace Remotely.Agent.Installer.Win.Services
Logger.Write(ex);
}
}
private async Task StopProcesses()
{
ProgressMessageChanged?.Invoke(this, "Stopping Remotely processes.");
var procs = Process.GetProcessesByName("Remotely_Agent").Concat(Process.GetProcessesByName("Remotely_ScreenCast"));
foreach (var proc in procs)
{
proc.Kill();
}
await Task.Delay(500);
}
private void StopService()
{
try

View File

@ -251,7 +251,7 @@ namespace Remotely.Agent.Installer.Win.ViewModels
private bool CheckParams()
{
var result = !string.IsNullOrWhiteSpace(OrganizationID) && !string.IsNullOrWhiteSpace(ServerUrl);
var result = !string.IsNullOrWhiteSpace(OrganizationID) || !string.IsNullOrWhiteSpace(ServerUrl);
if (!result)
{
MessageBoxWrapper.Show("Required settings are missing. Try re-downloading the installer.", "Invalid Installer", MessageBoxButton.OK, MessageBoxImage.Error);

View File

@ -43,13 +43,13 @@ namespace Remotely.Agent.Services
Logger.Write($"Service Updater: Downloading installer.");
if (OSUtils.IsWindows)
{
var filePath = Path.Combine(Path.GetTempPath(), "RemotelyUpdate.ps1");
var filePath = Path.Combine(Path.GetTempPath(), "Remotely_Installer.exe");
wc.DownloadFile(
ConfigService.GetConnectionInfo().Host + $"/API/ClientDownloads/{connectionInfo.OrganizationID}/Win10",
ConfigService.GetConnectionInfo().Host + $"/API/ClientDownloads/{connectionInfo.OrganizationID}/Windows",
filePath);
Process.Start("powershell.exe", $"-f \"{filePath}\"");
Process.Start(filePath, $"-install -quiet");
}
else if (OSUtils.IsLinux)
{

View File

@ -58,7 +58,7 @@ namespace Remotely.Server.API
byte[] fileBytes;
switch (platformID)
{
case "Win10":
case "Windows":
{
fileName = $"Remotely_Installer.exe";
var filePath = Path.Combine(HostEnv.WebRootPath, "Downloads", $"{fileName}");
@ -83,7 +83,21 @@ namespace Remotely.Server.API
}
break;
}
// TODO: Remove after a few versions.
case "Win10":
{
fileName = $"Install-{platformID}.ps1";
fileContents.AddRange(await System.IO.File.ReadAllLinesAsync(Path.Combine(HostEnv.WebRootPath, "Downloads", $"{fileName}")));
var hostIndex = fileContents.IndexOf("[string]$HostName = $null");
var orgIndex = fileContents.IndexOf("[string]$Organization = $null");
fileContents[hostIndex] = $"[string]$HostName = \"{scheme}://{Request.Host}\"";
fileContents[orgIndex] = $"[string]$Organization = \"{organizationID}\"";
fileBytes = System.Text.Encoding.UTF8.GetBytes(string.Join(Environment.NewLine, fileContents));
break;
}
case "Linux-x64":
{
fileName = "Install-Linux-x64.sh";