Skip to content

Commit

Permalink
Source Code
Browse files Browse the repository at this point in the history
  • Loading branch information
MistressPlague authored Mar 23, 2021
1 parent 8130161 commit 1f23934
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions Auto Restart Process/Auto Restart Process/Auto Restart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,16 @@ private void checkBox2_CheckedChanged(object sender, EventArgs e)
{
RegistryKey rk = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);

if (checkBox2.Checked)
if (rk != null)
{
rk.SetValue(Application.ExecutablePath, "\"" + Application.ExecutablePath + "\"");
}
else
{
rk.DeleteValue(Application.ExecutablePath, false);
if (checkBox2.Checked)
{
rk.SetValue(Application.ExecutablePath, "\"" + Application.ExecutablePath + "\"");
}
else
{
rk.DeleteValue(Application.ExecutablePath, false);
}
}

if (HasInit)
Expand All @@ -261,6 +264,7 @@ private void checkBox2_CheckedChanged(object sender, EventArgs e)
}
}

// ReSharper disable once MethodNameNotMeaningful
public void Log(string text)
{
LogBox.AppendText("[" + DateTime.Now.ToString("hh:MM:ss tt") + "] " + text + "\r\n");
Expand All @@ -287,11 +291,23 @@ private void RestartWorker_DoWork(object sender, System.ComponentModel.DoWorkEve
{
if (TimePassed.ElapsedMilliseconds >= (long)numericUpDown1.Value)
{
var Processes = Process.GetProcessesByName((Path.GetFileName(textBox1.Text) ?? "UnknownFileName")
.Replace((Path.GetExtension(textBox1.Text) ?? "UnknownExtension"), ""));

if (Processes.Length > 0)
{
Proc = Processes[0];

Log("Existing Process Found!");

goto AlreadyStarted;
}

Log("Restarting!");

ProcessStartInfo Info = new ProcessStartInfo
{
FileName = textBox1.Text,
FileName = textBox1.Text ?? "",
WorkingDirectory = Path.GetDirectoryName(textBox1.Text) ?? Environment.CurrentDirectory,
Arguments = textBox2.Text.Replace("%APPDIR%", Path.GetDirectoryName(textBox1.Text) ?? Environment.CurrentDirectory).Replace("%TIME%", DateTime.Now.ToString("dd MM ss tt")),
CreateNoWindow = checkBox3.Checked,
Expand All @@ -302,6 +318,8 @@ private void RestartWorker_DoWork(object sender, System.ComponentModel.DoWorkEve

Log("Process Started!");

AlreadyStarted:

Proc?.WaitForExit();

Log("Process Died" + (checkBox1.Checked ? " - Restarting Soon" : "") + "!");
Expand Down

0 comments on commit 1f23934

Please sign in to comment.