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:
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
: ABoolean
value indicating if the current process has full administrative rightsUACHelper.IsUACSupported
: ABoolean
value indicating if UAC virtualization is supported on the current machineUACHelper.IsDesktopOwner
: ABoolean
value indicating if the user that owns this process also owns the desktop sessionUACHelper.IsVirtualized
: ABoolean
value indicating if the current process started under UAC virtualizationUACHelper.IsAdministrator
: ABoolean
value indicating if the user that owns this process is a member of the 'Administrators' groupUACHelper.IsUACEnable
: ABoolean
value indicating if the UAC vitalization is enable on this machineUACHelper.DesktopOwner
: Returns aNTAccount
object containing information about the current desktop ownerUACHelper.Owner
: Returns aWindowsIdentity
object containing information about the current process owner
UACHelper.GetProcessDesktopOwner()
: Returns aNTAccount
object containing information about the desktop owner of a specificProcess
UACHelper.GetProcessOwner()
: Returns aWindowsIdentity
object containing information about the owner of a specificProcess
UACHelper.IsProcessElevated()
: Indicates if the passedProcess
started with elevated privilegesUACHelper.GetExpectedRunlevel()
: Checks a file and retrieve the expectedRunLevel
for it to startUACHelper.StartElevated()
: Starts a new elevatedProcess
with the start info providedUACHelper.StartLimited()
: Starts a newProcess
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 newProcess
with the start info provided and with the same rights as the current active shell processUACHelper.StartByShell()
: Starts a newProcess
with the start info provided using the current shell desktopIShellDispatch2.ShellExecute()
method.UACHelper.StartAndCopyProcessPermission()
: Starts a newProcess
with the start info provided and with the same rights as the mentionedProcess
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 system
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 theForm
and adds the UAC shield icon to the desiredButton
. Then calls theForm.ShowDialog
to display the form.WinForm.ShieldifyButton
: Changes theButton.FlatStyle
toFlatStyle.System
and adds the UAC shield icon
Form.ShowDialog
: Alias ofWinForm.ShieldifyForm
Form.ShieldifyButton
: Alias ofWinForm.ShieldifyButton
Check the 'UACHelper.Sample' for tons of examples on how to use the library.
- Restart the current program in Elevated Mode:
UACHelper.StartElevated(
new ProcessStartInfo(Assembly.GetExecutingAssembly().Location)
);
- Restart the current program in Limited Mode:
UACHelper.StartLimited(
new ProcessStartInfo(Assembly.GetExecutingAssembly().Location)
);
- Create an elevated Out-Of-Process COM object from a limited process - Read More: The COM Elevation Moniker
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.