Administration Elevation I'm looking into Administration Elevation and I've come up with a solution that seems like it's perfectly sane, but I'm still in the dark about the professional methods to accomplish this.

Is there a better way to do this or is this fine? 

using System;
using System.Diagnostics;
using System.Security.Principal;
using System.Windows.Forms;

namespace MyVendor.Installation
{
    static class Program
    {
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            if (!IsRunAsAdmin())           
            {
                Elevate();
                Application.Exit();
            }
            else
            {
                try
                {
                    Installer InstallerForm = new Installer();
                    Application.Run(InstallerForm);
                }
                catch (Exception e)
                {
                    //Display Exception message!

                    Logging.Log.Error("Unrecoverable exception:", e);
                    Application.Exit();
                }
            }
        }

        internal static bool IsRunAsAdmin()
        {
            var Principle = new WindowsPrincipal(WindowsIdentity.GetCurrent());
            return Principle.IsInRole(WindowsBuiltInRole.Administrator);
        }

        private static bool Elevate()
        {
            var SelfProc = new ProcessStartInfo
                {
                    UseShellExecute = true,
                    WorkingDirectory = Environment.CurrentDirectory,
                    FileName = Application.ExecutablePath,
                    Verb = "runas"
                };
            try
            {
                Process.Start(SelfProc);
                return true;
            }
            catch
            {
                Logging.Log.Error("Unable to elevate!");
                return false;
            }
        }
    }
}
You can create a manifest file and set the app to require administrative privileges. This will trigger the UAC user prompt with the dimmed screen when your application is run without requiring any code on your part.

See MSDN for the gory details:


  This file can be created by using any text editor. The application manifest file should have the same name as the target executable file with a .manifest extension.





&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
&lt;assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"&gt; 
  &lt;assemblyIdentity version="1.0.0.0"
     processorArchitecture="X86"
     name="&lt;your exec name minus extension&gt;"
     type="win32"/&gt; 
  &lt;description&gt;Description of your application&lt;/description&gt; 
  &lt;!-- Identify the application security requirements. --&gt;
  &lt;trustInfo xmlns="urn:schemas-microsoft-com:asm.v2"&gt;
    &lt;security&gt;
      &lt;requestedPrivileges&gt;
        &lt;requestedExecutionLevel
          level="requireAdministrator"
          uiAccess="false"/&gt;
        &lt;/requestedPrivileges&gt;
       &lt;/security&gt;
  &lt;/trustInfo&gt;
&lt;/assembly&gt;