-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathIntegration.cs
53 lines (51 loc) · 2 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
// 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.IO;
using System.Runtime.InteropServices;
namespace TrayApp
{
internal class Integration
{
public static void AddToStartup(bool add)
{
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)
{
File.Delete(startupFolder + "\\" + Program.ProductName + ".lnk");
if (add)
{
dynamic startupEntry = shell.CreateShortcut(startupFolder + "\\" + Program.ProductName + ".lnk");
try
{
var currentPathToExe = Directory.GetCurrentDirectory() + "\\" + Program.ProductName + ".exe";
startupEntry.TargetPath = currentPathToExe;
startupEntry.IconLocation = currentPathToExe;
startupEntry.Save();
}
finally
{
Marshal.FinalReleaseComObject(startupEntry);
}
}
}
}
finally
{
if (shell != null)
{
Marshal.FinalReleaseComObject(shell);
}
}
}
//LogStats();
}
}
}