C # compile a program running as an administrator,
Using System; using System. collections. generic; using System. linq; using System. windows. forms; namespace MyWebBrowser {static class Program {/// <summary> /// main entry point of the application. /// </Summary> [STAThread] static void Main () {// obtain the Windows User ID currently logged on: System. security. principal. windowsIdentity identity = System. security. principal. windowsIdentity. getCurrent (); System. security. principal. windowsPrincipal principal = new System. security. principal. windowsPrincipal (identity); // determines whether the current logon user is an administrator if (principal. isInRole (System. security. principal. windowsBuiltInRole. administrator) {// if it is an Administrator, run Application directly. enableVisualStyles (); Application. setCompatibleTextRenderingDefault (false); Application. run (new Form1 ();} else {// create the startup object System. diagnostics. processStartInfo startInfo = new System. diagnostics. processStartInfo (); // sets the running file startInfo. fileName = System. windows. forms. application. executablePath; // sets the startup action to ensure that startInfo is run as an administrator. verb = "runas"; // if it is not an administrator, start UAC System. diagnostics. process. start (startInfo); // exit System. windows. forms. application. exit ();}}}}