Files
EveryPublish/client/ui/Services/AutoStart.cs
T

32 lines
857 B
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Microsoft.Win32;
namespace EveryPublish.Client.Services;
/// <summary>开机自启(HKCU Run)</summary>
public static class AutoStart
{
private const string RunKey = @"Software\Microsoft\Windows\CurrentVersion\Run";
private const string ValueName = "EveryPublishClient";
public static bool IsEnabled()
{
using var key = Registry.CurrentUser.OpenSubKey(RunKey);
return key?.GetValue(ValueName) != null;
}
public static void SetEnabled(bool enabled)
{
using var key = Registry.CurrentUser.CreateSubKey(RunKey);
if (key == null) return;
if (enabled)
{
var exe = Environment.ProcessPath ?? "";
key.SetValue(ValueName, "\"" + exe + "\" --minimized");
}
else
{
key.DeleteValue(ValueName, false);
}
}
}