C # The program implementation code is run as the administrator by default,
Using System; using System. collections. generic; using System. linq; using System. windows. forms; namespace yyy {static class Program {/// <summary> /// main entry point of the application. /// </Summary> [STAThread] static void Main (string [] Args) {/*** start the application directly when the current user is an administrator * if not, start the program using the startup object to ensure that the System is running as an administrator * // obtain the Windows User ID currently logged on. security. principal. windowsIdentity identity = System. security. principal. windowsIdentity. getCurrent (); // create a Windows user topic Application. enableVisualStyles (); 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. 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; // set the startup parameter startInfo. arguments = String. join ("", Args); // 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 ();}}}}