Run process as administrator from a non-admin application

You must use ShellExecute. ShellExecute is the only API that knows how to launch Consent.exe in order to elevate. Sample (.NET) Source Code In C#, the way you call ShellExecute is to use Process.Start along with UseShellExecute = true: private void button1_Click(object sender, EventArgs e) { //Public domain; no attribution required. ProcessStartInfo info = new … Read more

Make Inno Setup installer request privileges elevation only when needed

Inno Setup 6 has a built-in support for non-administrative install mode. Basically, you can simply set PrivilegesRequiredOverridesAllowed: [Setup] PrivilegesRequiredOverridesAllowed=dialog Additionally, you will likely want to use the auto* variants of the constants. Notably the {autopf} for the DefaultDirName. [Setup] DefaultDirName={autopf}\My Program The following is my (now obsolete) solution for Inno Setup 5, based on @TLama’s … Read more

How do you de-elevate privileges for a child process

The solution for you is to use EXPLORER.exe process. The idea is to run the process in UN-ELEVATED mode, using windows’s file explorer process explorer.exe (info). Lets say the process that we want to launch is on $TEMP\MyUnElevatedProcess.exe. So, for NSIS code, I will just write: (but can be run in ANY language) Exec ‘”$WINDIR\explorer.exe” … Read more

dotnet core app run as administrator

I found the simplest workaround would be to add the app.manifest file with the setting like what in net framework app <requestedExecutionLevel level=”requireAdministrator” uiAccess=”false” /> then on your net core project file (.csproj in C# project) add the following: <PropertyGroup> <ApplicationManifest>app.manifest</ApplicationManifest> </PropertyGroup> *Worked in Console and WPF netcore 3.0

How can I run a child process that requires elevation and wait?

Use ShellExecuteEx, rather than ShellExecute. This function will provide a handle for the created process, which you can use to call WaitForSingleObject on that handle to block until that process terminates. Finally, just call CloseHandle on the process handle to close it. Sample code (most of the error checking is omitted for clarity and brevity): … Read more

Why do files get placed in “C:\Users\AppData\Local\VirtualStore\Program Files(x86)”?

An application that is not running with raised privileges should does not have access to the Program Files and Program Files (x86) directories. This is good for safety. In addition, in most cases when a developer tells his program to save data in the Program Files folder, for example, program settings, he has completely forgotten … Read more

Delphi: Prompt for UAC elevation when needed

i would relaunch yourself as elevated, passing command line parameters indicating what elevated thing you want to do. You can then jump right to the appropriate form, or just save your HKLM stuff. function RunAsAdmin(hWnd: HWND; filename: string; Parameters: string): Boolean; { See Step 3: Redesign for UAC Compatibility (UAC) http://msdn.microsoft.com/en-us/library/bb756922.aspx This code is released … Read more

How to use ServerManager to read IIS sites, not IIS express, from class library OR how do elevated processes handle class libraries?

Make sure you are adding the reference to the correct Microsoft.Web.Administration, should be v7.0.0.0 that is located under c:\windows\system32\inetsrv\ It looks like you are adding a reference to IIS Express’s Microsoft.Web.Administraiton which will give you that behavior

Java: run as administrator

You have to create a manifest file that specifies that your application needs administrator permissions. You can include the manifest in your exe or keep it as a separate file (yourapp.exe.manifest) http://msdn.microsoft.com/en-us/library/bb756929.aspx

How can I detect if my process is running UAC-elevated or not?

For those of us working in C#, in the Windows SDK there is a “UACDemo” application as a part of the “Cross Technology Samples”. They find if the current user is an administrator using this method: private bool IsAdministrator { get { WindowsIdentity wi = WindowsIdentity.GetCurrent(); WindowsPrincipal wp = new WindowsPrincipal(wi); return wp.IsInRole(WindowsBuiltInRole.Administrator); } } … Read more