-
Notifications
You must be signed in to change notification settings - Fork 1
/
StartupLauncher.cs
40 lines (36 loc) · 1.32 KB
/
StartupLauncher.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;
using Microsoft.Win32;
namespace Wellbeing
{
public static class StartupLauncher
{
//Startup registry key and value.
private const string StartupKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run";
private const string StartupValue = "DigitalWellbeing";
public static readonly string ExecutablePath = Path.Combine(Program.RootDirectory, Program.ExeName);
public static void SetLaunchOnStartup()
{
using RegistryKey key = Registry.CurrentUser.OpenSubKey(StartupKey, true)!;
if ((string)key.GetValue(StartupValue) != ExecutablePath)
{
Logger.Log("Registry path to executable was not correct. Rewriting.");
key.SetValue(StartupValue, ExecutablePath);
}
}
/*public static void ExcludeFromDefender()
{
var pInfo = new ProcessStartInfo("powershell")
{
UseShellExecute = false,
CreateNoWindow = true,
Verb = "runas",
Arguments = "-Command Add-MpPreference -ExclusionPath '" + ExecutablePath + "'"
};
var p = Process.Start(pInfo);
p.WaitForExit(5000);
}*/
}
}