-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWindowsFeatures.cs
46 lines (39 loc) · 1.41 KB
/
WindowsFeatures.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
45
46
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ImmersiveGaming
{
static class WindowsFeatures
{
static RegistryKey cuRunKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
static RegistryKey lmRunKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
public enum BootSegment
{
user,
global
}
private static RegistryKey getSegmentKey(BootSegment segment)
{
return segment == BootSegment.global ? lmRunKey : cuRunKey;
}
public static void AddToBoot(BootSegment segment, string valueName)
{
AddToBoot(segment, valueName, System.Reflection.Assembly.GetEntryAssembly().GetName().CodeBase);
}
public static void AddToBoot(BootSegment segment, string valueName, string exePath)
{
getSegmentKey(segment).SetValue(valueName, exePath);
}
public static void RemoveFromBoot(BootSegment segment, string valueName)
{
getSegmentKey(segment).DeleteValue(valueName);
}
public static bool StartsOnBoot(BootSegment segment, string valueName)
{
return getSegmentKey(segment).GetValue(valueName) != null;
}
}
}