-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUtils.cs
More file actions
89 lines (78 loc) · 2.88 KB
/
Utils.cs
File metadata and controls
89 lines (78 loc) · 2.88 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using deskdecorator.DekstopEngine.DesktopElements;
using deskdecorator.DekstopEngine;
using Microsoft.Win32;
using System;
using System.Diagnostics;
namespace deskdecorator.tools
{
static public class Utils
{
private const string RUN_KEY = @"Software\Microsoft\Windows\CurrentVersion\Run";
/// <summary>
/// Fügt die Anwendung dem Windows-Autostart hinzu.
/// </summary>
public static void AddToStartup(string appName)
{
try
{
string exePath = Application.ExecutablePath;
using RegistryKey key = Registry.CurrentUser.OpenSubKey(RUN_KEY, writable: true)!;
key.SetValue(appName, exePath);
Debug.WriteLine($"{appName} erfolgreich zum Autostart hinzugefügt.");
}
catch (Exception ex)
{
Debug.WriteLine($"[ERROR] Fehler beim Hinzufügen zum Autostart: {ex.Message}");
}
}
/// <summary>
/// Prüft, ob die Anwendung bereits im Autostart ist.
/// </summary>
public static bool IsInStartup(string appName)
{
try
{
using RegistryKey key = Registry.CurrentUser.OpenSubKey(RUN_KEY, writable: false)!;
return key.GetValue(appName) != null;
}
catch (Exception ex)
{
Debug.WriteLine($"[ERROR] Fehler beim Prüfen des Autostarts: {ex.Message}");
return false;
}
}
/// <summary>
/// Entfernt die Anwendung aus dem Autostart.
/// </summary>
public static void RemoveFromStartup(string appName)
{
try
{
using RegistryKey key = Registry.CurrentUser.OpenSubKey(RUN_KEY, writable: true)!;
if (key.GetValue(appName) != null)
{
key.DeleteValue(appName);
Debug.WriteLine($"[INFO] {appName} aus dem Autostart entfernt.");
}
else
{
Debug.WriteLine($"[INFO] {appName} war nicht im Autostart eingetragen.");
}
}
catch (Exception ex)
{
Debug.WriteLine($"[ERROR] Fehler beim Entfernen aus dem Autostart: {ex.Message}");
}
}
public static void RefreshComboBox()
{
Engine.combox_EditItemSelector.Items.Clear();
foreach (var element in Manager.Labels)
Engine.combox_EditItemSelector.Items.Add(element.Description);
if (Engine.combox_EditItemSelector.Items.Count == 0)
Engine.combox_EditItemSelector.Items.Add("No item selected");
Engine.combox_EditItemSelector.SelectedIndex = 0;
Debug.WriteLine($"[INFO] Item Selection refreshed!");
}
}
}