-
Notifications
You must be signed in to change notification settings - Fork 0
/
Startup.cs
32 lines (29 loc) · 1.14 KB
/
Startup.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
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ScreenRotator {
class Startup {
//Startup registry key and value
private static readonly string StartupKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
private static readonly string StartupValue = "Screen Rotator";
internal static void SetStartup(bool start) {
if (start) {
//Set the application to run at startup
RegistryKey key = Registry.CurrentUser.OpenSubKey(StartupKey, true);
key.SetValue(StartupValue, Application.ExecutablePath.ToString());
} else {
RegistryKey key = Registry.CurrentUser.OpenSubKey(StartupKey, true);
key.DeleteValue(StartupValue);
}
}
internal static bool GetStartup() {
//Set the application to run at startup
RegistryKey key = Registry.CurrentUser.OpenSubKey(StartupKey, false);
return (key.GetValue(StartupValue) != null);
}
}
}