A helper class library to detect, manage and use UAC functionalities in your program.
A helper class library to detect, manage and use UAC functionalities in your program
This library is available as a NuGet package at nuget.org.
--OR--
You can always donate your time by contributing to the project or by introducing it to others.
Currently there are three main classes in this library:
UACHelper.UACHelper
This static class contains properties about the current state of the application as well as providing methods to get information about other processes and starting new ones.
UACHelper.IsElevated
: A Boolean
value indicating if the current process has full administrative rightsUACHelper.IsUACSupported
: A Boolean
value indicating if UAC virtualization is supported on the current machineUACHelper.IsDesktopOwner
: A Boolean
value indicating if the user that owns this process also owns the desktop sessionUACHelper.IsVirtualized
: A Boolean
value indicating if the current process started under UAC virtualizationUACHelper.IsAdministrator
: A Boolean
value indicating if the user that owns this process is a member of the 'Administrators' groupUACHelper.IsUACEnable
: A Boolean
value indicating if the UAC vitalization is enable on this machineUACHelper.DesktopOwner
: Returns a NTAccount
object containing information about the current desktop ownerUACHelper.Owner
: Returns a WindowsIdentity
object containing information about the current process ownerUACHelper.GetProcessDesktopOwner()
: Returns a NTAccount
object containing information about the desktop owner of a specific Process
UACHelper.GetProcessOwner()
: Returns a WindowsIdentity
object containing information about the owner of a specific Process
UACHelper.IsProcessElevated()
: Indicates if the passed Process
started with elevated privilegesUACHelper.GetExpectedRunlevel()
: Checks a file and retrieve the expected RunLevel
for it to startUACHelper.StartElevated()
: Starts a new elevated Process
with the start info providedUACHelper.StartLimited()
: Starts a new Process
with the start info provided and with the limited access rightsUACHelper.StartLimitedTask()
: Starts a new process with the task info provided and with the limited access rights using TaskScheduler serviceUACHelper.StartWithShell()
: Starts a new Process
with the start info provided and with the same rights as the current active shell processUACHelper.StartByShell()
: Starts a new Process
with the start info provided using the current shell desktop IShellDispatch2.ShellExecute()
method.UACHelper.StartAndCopyProcessPermission()
: Starts a new Process
with the start info provided and with the same rights as the mentioned Process
UACHelper.AAMSettings
This static class contains settings of the "Admin Approval Mode"
AAMSettings.IsEnable
: Enables the "administrator in Admin Approval Mode" user type while also enabling all other User Account Control (UAC) policies. Requires restart.AAMSettings.EnforceAdminCodeSignatures
: Enforce cryptographic signatures on any interactive application that requests elevation of privilege.AAMSettings.ForceDimPromptScreen
: Will force all UAC prompts to happen on the user's secure desktop.AAMSettings.IsVirtualizationEnable
: Enables the redirection of legacy application File and Registry writes that would normally fail as standard user to a user-writable data location.AAMSettings.IsInstallerDetectionEnable
: Used to heuristically detect applications that require an elevation of privilege to install.AAMSettings.UserPromptBehavior
: AAM behaviors regarding users running elevated applicationsAAMSettings.AdminPromptBehavior
: AAM behaviors regarding administrators' changes to systemUACHelper.WinForm
This static class contains multiple methods to add the UAC shield icon to the buttons, forms and native dialogs
WinForm.ShieldifyNativeDialog
: Goes through the controls in the native dialog and adds the UAC shield icon to the desired native button.WinForm.ShieldifyNativeButton
: Adds the UAC shield icon to the buttonWinForm.ShieldifyForm
: Goes through the controls in the Form
and adds the UAC shield icon to the desired Button
. Then calls the Form.ShowDialog
to display the form.WinForm.ShieldifyButton
: Changes the Button.FlatStyle
to FlatStyle.System
and adds the UAC shield iconForm.ShowDialog
: Alias of WinForm.ShieldifyForm
Form.ShieldifyButton
: Alias of WinForm.ShieldifyButton
Check the 'UACHelper.Sample' for tons of examples on how to use the library.
UACHelper.StartElevated(
new ProcessStartInfo(Assembly.GetExecutingAssembly().Location)
);
UACHelper.StartLimited(
new ProcessStartInfo(Assembly.GetExecutingAssembly().Location)
);
The MIT License (MIT)
Copyright (c) 2016-2020 Soroush
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.