BlackSharp.Platform.Startup
1.3.2
Prefix Reserved
dotnet add package BlackSharp.Platform.Startup --version 1.3.2
NuGet\Install-Package BlackSharp.Platform.Startup -Version 1.3.2
<PackageReference Include="BlackSharp.Platform.Startup" Version="1.3.2" />
<PackageVersion Include="BlackSharp.Platform.Startup" Version="1.3.2" />
<PackageReference Include="BlackSharp.Platform.Startup" />
paket add BlackSharp.Platform.Startup --version 1.3.2
#r "nuget: BlackSharp.Platform.Startup, 1.3.2"
#:package BlackSharp.Platform.Startup@1.3.2
#addin nuget:?package=BlackSharp.Platform.Startup&version=1.3.2
#tool nuget:?package=BlackSharp.Platform.Startup&version=1.3.2
<h1 align="center">BlackSharp.Platform.Startup</h1>
<p align="center"> <img src="https://raw.githubusercontent.com/Blacktempel/BlackSharp/master/Assets/BlackSharpFull.png" width="128" height="128" alt="BlackSharp.Platform.Startup logo"/> </p>
BlackSharp.Platform.Startup registers application commands for system boot or
user login.
Features
- Windows boot tasks that run as
SYSTEMthrough Task Scheduler - Non-elevated Windows login tasks for the current user or a specified group
- Linux system-wide boot registration with systemd
- XDG desktop autostart entries for graphical Linux sessions
- Separate executable paths, arguments and working directories through
StartupCommand
Supported .NET versions
| .NET version | Support |
|---|---|
| .NET Framework 4.7.2 | ✅ |
| .NET Framework 4.8.1 | ✅ |
| .NET Standard 2.0 | ✅ |
| .NET 8 | ✅ |
| .NET 9 | ✅ |
| .NET 10 | ✅ |
| .NET 11 | ✅ |
NuGet
dotnet add package BlackSharp.Platform.Startup
Supported platforms
| Operating system | Support | Boot registration | Login registration |
|---|---|---|---|
| Windows | ✅ | Task Scheduler boot task | Task Scheduler login task |
| Linux | ✅ | System-level systemd service | XDG desktop autostart file |
| Other | ❌ | Not supported | Not supported |
Boot registration needs administrative privileges. On Linux, a writable
/etc/systemd/system and a working systemctl are required for system-level
registration. XDG autostart requires a desktop environment that reads those
entries and write access to the selected autostart directory. Windows login
tasks run non-elevated; creating or removing a task still requires permission
to manage that task.
ProcessPrivilege.IsElevated checks the current process for an administrator
token on Windows or an effective user ID of zero on Linux.
Usage
Register startup at graphical login
Call this when the user enables or disables startup in your application's settings. Supply the absolute path to the installed executable and pass each argument separately. This example uses the platform checks in modern .NET.
using BlackSharp.Platform.Startup.Models;
using BlackSharp.Platform.Startup.Platform.Linux;
using BlackSharp.Platform.Startup.Platform.Windows;
static void SetStartAtLogin(string executablePath, bool enabled)
{
var command = new StartupCommand(
executablePath,
new[] { "--minimized" },
Path.GetDirectoryName(executablePath)!);
if (OperatingSystem.IsWindows())
{
WindowsTaskStartupRegistration.SetCurrentUserLoginTaskEnabled(
"ExampleApp", "Start Example App at login", command, enabled);
}
else if (OperatingSystem.IsLinux())
{
var directory = LinuxDesktopAutostartRegistration.GetCurrentUserAutostartDirectory();
var desktopEntryPath = Path.Combine(directory, "example-app.desktop");
LinuxDesktopAutostartRegistration.SetEnabled(
desktopEntryPath, "Example App", command, enabled);
}
else
{
throw new PlatformNotSupportedException();
}
}
Configure a boot command
Use WindowsTaskStartupRegistration.SetBootTaskEnabled or
LinuxSystemdStartupRegistration.SetEnabled for a non-interactive boot
process. Use a task or unit name owned by your application. Boot registration
runs with system privileges; place the executable in a trusted installation
directory.
On Linux, you can preview the unit:
using BlackSharp.Platform.Startup.Models;
using BlackSharp.Platform.Startup.Platform.Linux;
var command = new StartupCommand(
"/opt/example-agent/example-agent",
Array.Empty<string>(),
"/opt/example-agent");
Console.WriteLine(LinuxSystemdStartupRegistration.CreateUnitContent(
"Example background agent", command));
The systemd registration method accepts a simple unit name ending in
.service. It enables the unit for boot. Disabling it removes the registration.
Support and license
Report issues in the BlackSharp issue tracker. Licensed under the Mozilla Public License 2.0.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. 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. net11.0 is compatible. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 is compatible. net48 was computed. net481 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.7.2
- BlackSharp.Core (>= 1.3.2)
- TaskScheduler (>= 2.12.2)
-
.NETFramework 4.8.1
- BlackSharp.Core (>= 1.3.2)
- TaskScheduler (>= 2.12.2)
-
.NETStandard 2.0
- BlackSharp.Core (>= 1.3.2)
- TaskScheduler (>= 2.12.2)
-
net10.0
- BlackSharp.Core (>= 1.3.2)
- TaskScheduler (>= 2.12.2)
-
net11.0
- BlackSharp.Core (>= 1.3.2)
- TaskScheduler (>= 2.12.2)
-
net8.0
- BlackSharp.Core (>= 1.3.2)
- TaskScheduler (>= 2.12.2)
-
net9.0
- BlackSharp.Core (>= 1.3.2)
- TaskScheduler (>= 2.12.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.