RunAtStartup 6.0.0
dotnet add package RunAtStartup --version 6.0.0
NuGet\Install-Package RunAtStartup -Version 6.0.0
<PackageReference Include="RunAtStartup" Version="6.0.0" />
<PackageVersion Include="RunAtStartup" Version="6.0.0" />
<PackageReference Include="RunAtStartup" />
paket add RunAtStartup --version 6.0.0
#r "nuget: RunAtStartup, 6.0.0"
#:package RunAtStartup@6.0.0
#addin nuget:?package=RunAtStartup&version=6.0.0
#tool nuget:?package=RunAtStartup&version=6.0.0
RunAtStartup
Register an unpackaged executable to start when the current user logs in, on Windows, Linux and macOS.
Usage
using RunAtStartup;
if (StartupService.IsSupported && Environment.ProcessPath is { } executablePath)
{
// name: Windows Run value name, Linux .desktop file name and Name field
// macOSLabel: LaunchAgent Label and .plist file name
StartupService service = new("MyApp", "com.example.myapp");
// Show the state of a "run at login" toggle
bool enabled = service.Check(executablePath, "--minimized");
// Turn it on or off
service.Set(executablePath, "--minimized");
service.Delete();
// Point a registration left by an older install location at this executable
if (service.Exists() && !service.Check(executablePath, "--minimized"))
{
service.Set(executablePath, "--minimized");
}
}
Exists()returns whether a registration with this name exists, whatever it starts.Check(path, args)returns whether the registration exists and is exactly whatSet(path, args)would write. Together withExists(), it detects a registration left behind by an older install location.Set(path, args)creates or replaces the registration.Delete()removes the registration and does nothing if there is none.
name and macOSLabel cannot be empty or contain control characters, / or \. name also cannot start with ., because the systemd XDG autostart generator skips hidden files on Linux.
The executable path and arguments are always passed explicitly; the library never reads Environment.ProcessPath.
Read and write failures are not caught: IOException, UnauthorizedAccessException and, on Windows, SecurityException propagate to the caller. On other platforms every instance method throws PlatformNotSupportedException.
Platforms
| Platform | Registration | Command line |
|---|---|---|
| Windows | HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run, value name |
The path is always quoted; an argument is quoted and escaped by the CommandLineToArgvW rules only when it is empty or contains whitespace or ". Check compares case-insensitively. |
| Linux | $XDG_CONFIG_HOME/autostart/{name}.desktop (~/.config/autostart when unset or not absolute) |
Exec is escaped by the Desktop Entry Specification. Check compares the whole file ordinally. |
| macOS | ~/Library/LaunchAgents/{macOSLabel}.plist |
ProgramArguments holds the path and each argument; RunAtLoad is true. Check compares the whole file ordinally. |
On macOS the file is only written; launchctl is not called, so the change takes effect at the next login.
Not supported
- Registering for all users (
HKEY_LOCAL_MACHINE,/etc/xdg/autostart,/Library/LaunchAgents). - Packaged apps: MSIX
StartupTask, the Flatpak background portal and macOSSMAppService. - Platforms other than Windows, Linux and macOS.
Requirements
.NET 10 or later.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories (2)
Showing the top 2 popular GitHub repositories that depend on RunAtStartup:
| Repository | Stars |
|---|---|
|
HMBSbige/ShadowsocksR-Windows
Ship of Theseus
|
|
|
HMBSbige/BilibiliLiveRecordDownLoader
跨平台 B 站直播录制工具
|