-
Notifications
You must be signed in to change notification settings - Fork 1
/
Autostart.cs
42 lines (36 loc) · 1.11 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
using Microsoft.Win32;
using System;
namespace Discord_Custom_RPC
{
internal class Autostart
{
//Добавление в автозапуск
public static bool SetAutoStart(bool set)
{
const string appName = "Discord Custom RPC";
try
{
RegistryKey? registryKey = Registry.CurrentUser.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
if (set)
{
string? exePath = System.Diagnostics.Process.GetCurrentProcess().MainModule?.FileName;
if (exePath != null)
{
registryKey?.SetValue(appName, exePath);
return true;
}
else return false;
}
else
{
registryKey?.DeleteValue(appName, false);
return true;
}
}
catch (Exception)
{
return false;
}
}
}
}