Uninstaller bug fix.

This commit is contained in:
Jared Goodwin 2019-04-06 13:29:47 -07:00
parent 6da42e50c5
commit 21ace2fc33
3 changed files with 13 additions and 29 deletions

View File

@ -74,7 +74,7 @@ namespace Remotely_Agent.Services
if (!IsServerVerified)
{
Logger.Write($"Command attempted before server was verified. Mode: {mode}. Command: {command}. Sender: {senderConnectionID}");
Uninstaller.UninstallClient();
Uninstaller.UninstallAgent();
return;
}
try
@ -229,7 +229,7 @@ namespace Remotely_Agent.Services
});
hubConnection.On("UninstallClient", () =>
{
Uninstaller.UninstallClient();
Uninstaller.UninstallAgent();
});
hubConnection.On("RemoteControl", async (string requesterID, string serviceID) =>
@ -237,7 +237,7 @@ namespace Remotely_Agent.Services
if (!IsServerVerified)
{
Logger.Write("Remote control attempted before server was verified.");
Uninstaller.UninstallClient();
Uninstaller.UninstallAgent();
return;
}
try
@ -288,7 +288,7 @@ namespace Remotely_Agent.Services
if (!IsServerVerified)
{
Logger.Write("Remote control attempted before server was verified.");
Uninstaller.UninstallClient();
Uninstaller.UninstallAgent();
return;
}
try
@ -347,7 +347,7 @@ namespace Remotely_Agent.Services
else
{
Logger.Write($"Server sent an incorrect verification token. Token Sent: {verificationToken}.");
Uninstaller.UninstallClient();
Uninstaller.UninstallAgent();
return;
}
});

View File

@ -11,41 +11,25 @@ namespace Remotely_Agent.Services
{
public class Uninstaller
{
public static void UninstallClient()
public static void UninstallAgent()
{
if (OSUtils.IsWindows)
{
Process.Start("cmd.exe", "/c sc delete Remotely_Service");
var tempFilePath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName()) + ".ps1";
var deleteTime = DateTime.Now.AddMinutes(2).ToString("HH:mm");
var currentDir = AppDomain.CurrentDomain.BaseDirectory;
var ps = PowerShell.Create();
ps.AddScript($@"
$Success = $false;
$Count = 0;
while ((Test-Path ""{currentDir}"") -eq $true -and $Count -lt 10) {{
try {{
Get-Process -Name Agent | Stop-Process -Force;
Start-Sleep -Seconds 3;
Remove-Item ""{currentDir}"" -Force -Recurse;
$Count++;
continue;
}}
catch{{
continue;
}}
}}
");
ps.Invoke();
Process.Start("cmd.exe", $"/c timeout 5 & rd /s /q \"{currentDir}\"");
}
else if (OSUtils.IsLinux)
{
var users = OSUtils.StartProcessWithResults("users", "");
var username = users?.Split()?.FirstOrDefault()?.Trim();
Process.Start("systemctl", "stop remotely-client").WaitForExit();
Process.Start("sudo", "systemctl stop remotely-agent").WaitForExit();
Directory.Delete("/usr/local/bin/Remotely", true);
File.Delete("/etc/systemd/system/remotely-client.service");
Process.Start("systemctl", "daemon-reload").WaitForExit();
File.Delete("/etc/systemd/system/remotely-agent.service");
Process.Start("sudo", "systemctl daemon-reload").WaitForExit();
}
Environment.Exit(0);
}
}
}

View File

@ -1 +1 @@
2019.04.06.0044
2019.04.06.1318