mirror of
https://github.com/jkocon/g-helper.git
synced 2026-02-23 13:00:52 +01:00
Startup admin restarter
This commit is contained in:
@@ -345,7 +345,7 @@ namespace GHelper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool IsUserAdministrator()
|
public static bool IsUserAdministrator()
|
||||||
{
|
{
|
||||||
WindowsIdentity identity = WindowsIdentity.GetCurrent();
|
WindowsIdentity identity = WindowsIdentity.GetCurrent();
|
||||||
WindowsPrincipal principal = new WindowsPrincipal(identity);
|
WindowsPrincipal principal = new WindowsPrincipal(identity);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Microsoft.Win32.TaskScheduler;
|
using GHelper;
|
||||||
|
using Microsoft.Win32.TaskScheduler;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Security.Principal;
|
using System.Security.Principal;
|
||||||
|
|
||||||
@@ -28,6 +29,9 @@ public class Startup
|
|||||||
td.Triggers.Add(new LogonTrigger { UserId = userId });
|
td.Triggers.Add(new LogonTrigger { UserId = userId });
|
||||||
td.Actions.Add(strExeFilePath);
|
td.Actions.Add(strExeFilePath);
|
||||||
|
|
||||||
|
if (Program.IsUserAdministrator())
|
||||||
|
td.Principal.RunLevel = TaskRunLevel.Highest;
|
||||||
|
|
||||||
td.Settings.StopIfGoingOnBatteries = false;
|
td.Settings.StopIfGoingOnBatteries = false;
|
||||||
td.Settings.DisallowStartIfOnBatteries = false;
|
td.Settings.DisallowStartIfOnBatteries = false;
|
||||||
td.Settings.ExecutionTimeLimit = TimeSpan.Zero;
|
td.Settings.ExecutionTimeLimit = TimeSpan.Zero;
|
||||||
@@ -41,7 +45,10 @@ public class Startup
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Can't create a start up task. Try running Task Scheduler by hand and manually deleting GHelper task if it exists there.", "Scheduler Error", MessageBoxButtons.OK);
|
if (Program.IsUserAdministrator())
|
||||||
|
MessageBox.Show("Can't create a start up task. Try running Task Scheduler by hand and manually deleting GHelper task if it exists there.", "Scheduler Error", MessageBoxButtons.OK);
|
||||||
|
else
|
||||||
|
Program.RunAsAdmin();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,7 +64,10 @@ public class Startup
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Can't remove task. Try running Task Scheduler by hand and manually deleting GHelper task if it exists there.", "Scheduler Error", MessageBoxButtons.OK);
|
if (Program.IsUserAdministrator())
|
||||||
|
MessageBox.Show("Can't remove task. Try running Task Scheduler by hand and manually deleting GHelper task if it exists there.", "Scheduler Error", MessageBoxButtons.OK);
|
||||||
|
else
|
||||||
|
Program.RunAsAdmin();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user