forked from haidarn2/Spoti15
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathAutostart.cs
44 lines (37 loc) · 1.14 KB
/
Autostart.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
41
42
43
44
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
namespace Spoti15
{
class Autostart
{
private const string RunLocation = @"Software\Microsoft\Windows\CurrentVersion\Run";
private const string KeyName = "Spoti15Autostart";
static private string RunValue()
{
return "\"" + Application.ExecutablePath + "\" -autostart";
}
static public bool IsEnabled()
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(RunLocation);
if (key == null)
return false;
string val = (string)key.GetValue(KeyName);
if (val == null)
return false;
return val == RunValue();
}
static public void Enable()
{
RegistryKey key = Registry.CurrentUser.CreateSubKey(RunLocation);
key.SetValue(KeyName, RunValue());
}
static public void Disable()
{
RegistryKey key = Registry.CurrentUser.CreateSubKey(RunLocation);
key.DeleteValue(KeyName);
}
}
}