How do you request administrator permissions using NSIS?

Outfile RequireAdmin.exe RequestExecutionLevel admin ;Require admin rights on NT6+ (When UAC is turned on) !include LogicLib.nsh Function .onInit UserInfo::GetAccountType pop $0 ${If} $0 != “admin” ;Require admin rights on NT4+ MessageBox mb_iconstop “Administrator rights required!” SetErrorLevel 740 ;ERROR_ELEVATION_REQUIRED Quit ${EndIf} FunctionEnd Page InstFiles Section SectionEnd is the basic code I usually recommend to make sure … Read more

How to build RUNAS /NETONLY functionality into a (C#/.NET/WinForms) program?

I know this is an old thread, but it was very useful. I have the exact same situation as Cade Roux, as I wanted /netonly style functionality. John Rasch’s answer works with one small modification!!! Add the following constant (around line 102 for consistency): private const int LOGON32_LOGON_NEW_CREDENTIALS = 9; Then change the call to … Read more

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