forked from XenHat/TrayReader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Integration.cs
72 lines (68 loc) · 2.62 KB
/
Integration.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// This is an open source non-commercial project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
namespace TrayApp
{
internal class Integration
{
private static readonly ProcessStartInfo PowerCfgStartInfo = new ProcessStartInfo
{
FileName = "powercfg.exe",
Arguments = "-setactive 381b4222-f694-41f0-9685-ff5bb260df2e",
CreateNoWindow = true
};
public static void AddToStartup()
{
string startupFolder = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
// Empty a few directories. Yes. If your shit is missing, this is the line that does it.
Type t = Type.GetTypeFromCLSID(new Guid("72C24DD5-D70A-438B-8A42-98424B88AFB8"));
if (t != null)
{
dynamic shell = Activator.CreateInstance(t);
try
{
if (shell != null)
{
string LinkName = startupFolder + "\\" + Program.ProductName + ".lnk";
File.Delete(LinkName);
if (TrayApp.Properties.Settings.Default.AutomaticStartup)
{
dynamic startupEntry = shell.CreateShortcut(LinkName);
try
{
var currentPathToExe = System.Reflection.Assembly.GetExecutingAssembly().Location;
startupEntry.TargetPath = currentPathToExe;
startupEntry.IconLocation = currentPathToExe;
startupEntry.Save();
}
finally
{
Marshal.FinalReleaseComObject(startupEntry);
}
}
}
}
finally
{
if (shell != null)
{
Marshal.FinalReleaseComObject(shell);
}
}
}
//LogStats();
}
public static void SetPowerPlanToOnDemand()
{
Process powercfgProcess = new Process
{
StartInfo = PowerCfgStartInfo,
};
powercfgProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
powercfgProcess.Start();
}
}
}