diff -r 61e2e2d41c0a -r 787dee27fc0a Server/Program.cs --- a/Server/Program.cs Sat Jan 17 18:26:41 2015 +0100 +++ b/Server/Program.cs Sun Jan 18 12:35:22 2015 +0100 @@ -3,6 +3,9 @@ using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; +using System.Security.Principal; +using System.Diagnostics; +using System.Reflection; namespace SharpDisplayManager { @@ -16,7 +19,35 @@ /// [STAThread] static void Main() - { + { + + /* + if (!IsRunAsAdministrator()) + { + var processInfo = new ProcessStartInfo(Assembly.GetExecutingAssembly().CodeBase); + + // The following properties run the new process as administrator + processInfo.UseShellExecute = true; + processInfo.Verb = "runas"; + + // Start the new process + try + { + Process.Start(processInfo); + } + catch (Exception) + { + // The user did not allow the application to run as administrator + MessageBox.Show("Sorry, this application must be run as Administrator."); + } + + // Shut down the current process + Application.Exit(); + return; + //Application.Current.Shutdown(); + }*/ + + Application.ApplicationExit += new EventHandler(OnApplicationExit); // Application.EnableVisualStyles(); @@ -25,6 +56,16 @@ Application.Run(iMainForm); } + + + static private bool IsRunAsAdministrator() + { + var wi = WindowsIdentity.GetCurrent(); + var wp = new WindowsPrincipal(wi); + + return wp.IsInRole(WindowsBuiltInRole.Administrator); + } + /// /// Occurs after form closing. ///