WindowsPrivilegedActions class

Namespace Runic.Platform.Windows.Elevation in Runic.Platform.Windows.Elevation 0.23.0

public static class WindowsPrivilegedActions

Runs declared privileged actions on Windows through a helper elevated with UAC.

Remarks

Each run starts the action's helper with ShellExecuteExW and the runas verb, which shows the UAC prompt. The helper connects to a named pipe the application created for this run, reports whether it runs elevated and accepts the action, and streams its output back; the application cancels over the same pipe. The helper must be a NativeAOT build that calls ElevatedHelper.Match, installed in a directory only administrators can change, such as Program Files.

UAC reports a declined prompt and a standard user's closed credential prompt the same way, so both are PlatformFailureCode.UserDismissed; PlatformFailureCode.PermissionDenied means a policy refused the elevation. With UAC off, runas starts the helper without elevation; it reports that, and the result is PlatformUnavailableReason.BackendUnavailable.

Fields

TerminatedExitCode

public const int TerminatedExitCode = 1223

The exit code of a helper terminated after WindowsElevationOptions.TerminateAfterCancellation: ERROR_CANCELLED.

Methods

Create

public static IDesktopPrivilegedActions Create(IEnumerable<PrivilegedActionDeclaration> actions, WindowsElevationOptions? options = null)

Creates the provider for actions, usually the generated PrivilegedActions.All.

Parameters

actions

The declared actions.

options

Usually the generated PrivilegedActions.WindowsElevation.

Exceptions

ArgumentException

Two actions share an ID or a verb, an action without a verb is not the only one, or a helper path or WindowsElevationOptions.ApplicationDirectory is not a local, normalized path.

Remarks

Off Windows, the result reports every request unavailable with PlatformUnavailableReason.BackendUnavailable.