Migration to Visual Studio 2015.
SharpLibDisplay: Now closing client upon server request.
1 // UacHelpers.CppLibrary.h
5 using namespace System::Diagnostics;
6 using namespace System::Security::Principal;
11 ///Provides facilities for enabling and disabling User Account Control (UAC),
12 ///determining elevation and virtualization status, and launching a process
13 ///under elevated credentials.
16 ///Note that there's a delicate scenario where the registry key has already been
17 ///changed, but the user has not logged off yet so the token hasn't been filtered.
18 ///In that case, we will think that UAC is on but the user is not an admin (because
19 ///the token is not a split token).
21 public ref class UserAccountControl abstract sealed
25 ///Returns <b>true</b> if the current user has administrator privileges.
28 ///If UAC is on, then this property will return <b>true</b> even if the
29 ///current process is not running elevated. If UAC is off, then this
30 ///property will return <b>true</b> if the user is part of the built-in
31 ///<i>Administrators</i> group.
33 static property bool IsUserAdmin
39 ///Returns <b>true</b> if User Account Control (UAC) is enabled on
43 ///This value is obtained by checking the LUA registry key. It is possible
44 ///that the user has not restarted the machine after enabling/disabling UAC.
45 ///In that case, the value of the registry key does not reflect the true state
46 ///of affairs. It is possible to devise a custom solution that would provide
47 ///a mechanism for tracking whether a restart occurred since UAC settings were
48 ///changed (using the RunOnce mechanism, temporary files, or volatile registry keys).
50 static property bool IsUacEnabled
56 ///Returns <b>true</b> if the current process is using UAC virtualization.
59 ///Under UAC virtualization, file system and registry accesses to specific
60 ///locations performed by an application are redirected to provide backwards-
61 ///compatibility. 64-bit applications or applications that have an associated
62 ///manifest do not enjoy UAC virtualization because they are assumed to be
63 ///compatible with Vista and UAC.
65 static property bool IsCurrentProcessVirtualized
71 ///Returns <b>true</b> if the current process is elevated, i.e. if the process
72 ///went through an elevation consent phase.
75 ///This property will return <b>false</b> if UAC is disabled and the process
76 ///is running as admin. It only determines whether the process went through
77 ///the elevation procedure.
79 static property bool IsCurrentProcessElevated
85 ///Disables User Account Control by changing the LUA registry key.
86 ///The changes do not have effect until the system is restarted.
88 static void DisableUac();
91 ///Disables User Account Control and restarts the system.
93 static void DisableUacAndRestartWindows();
96 ///Enables User Account Control by changing the LUA registry key.
97 ///The changes do not have effect until the system is restarted.
99 static void EnableUac();
102 ///Enables User Account Control and restarts the system.
104 static void EnableUacAndRestartWindows();
107 ///Creates a process under the elevated token, regardless of UAC settings
108 ///or the manifest associated with that process.
110 ///<param name="exePath">The path to the executable file.</param>
111 ///<param name="arguments">The command-line arguments to pass to the process.</param>
112 ///<returns>A <see cref="Process"/> object representing the newly created process.</returns>
113 static Process^ CreateProcessAsAdmin(System::String^ exePath, System::String^ arguments);
116 ///Creates a process under the standard user if the current process is elevated. The identity
117 ///of the standard user is determined by retrieving the user token of the currently running Explorer
118 //(shell) process. If the current process is not elevated, the standard user is used.
120 ///<param name="exePath">The path to the executable file.</param>
121 ///<param name="arguments">The command-line arguments to pass to the process.</param>
122 ///<returns>A <see cref="Process"/> object representing the newly created process.</returns>
123 static Process^ CreateProcessAsStandardUser(System::String^ exePath, System::String^ arguments);
126 static int GetProcessTokenElevationType();
127 static void SetUacRegistryValue(bool enable);
128 static void RestartWindows();
130 static System::String^ UacRegistryKey = "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System";
131 static System::String^ UacRegistryValue = "EnableLUA";
133 } // end namespace UacHelpers