Server/Program.cs
changeset 92 787dee27fc0a
parent 86 829dd13b1048
child 123 0df386e37e29
     1.1 --- a/Server/Program.cs	Sat Jan 17 18:26:41 2015 +0100
     1.2 +++ b/Server/Program.cs	Sun Jan 18 12:35:22 2015 +0100
     1.3 @@ -3,6 +3,9 @@
     1.4  using System.Linq;
     1.5  using System.Threading.Tasks;
     1.6  using System.Windows.Forms;
     1.7 +using System.Security.Principal;
     1.8 +using System.Diagnostics;
     1.9 +using System.Reflection;
    1.10  
    1.11  namespace SharpDisplayManager
    1.12  {
    1.13 @@ -16,7 +19,35 @@
    1.14          /// </summary>
    1.15          [STAThread]
    1.16          static void Main()
    1.17 -        {	
    1.18 +        {
    1.19 +
    1.20 +			/*
    1.21 +			if (!IsRunAsAdministrator())
    1.22 +			{
    1.23 +				var processInfo = new ProcessStartInfo(Assembly.GetExecutingAssembly().CodeBase);
    1.24 +
    1.25 +				// The following properties run the new process as administrator
    1.26 +				processInfo.UseShellExecute = true;
    1.27 +				processInfo.Verb = "runas";
    1.28 +
    1.29 +				// Start the new process
    1.30 +				try
    1.31 +				{
    1.32 +					Process.Start(processInfo);
    1.33 +				}
    1.34 +				catch (Exception)
    1.35 +				{
    1.36 +					// The user did not allow the application to run as administrator
    1.37 +					MessageBox.Show("Sorry, this application must be run as Administrator.");
    1.38 +				}
    1.39 +
    1.40 +				// Shut down the current process
    1.41 +				Application.Exit();
    1.42 +				return;
    1.43 +				//Application.Current.Shutdown();
    1.44 +			}*/
    1.45 +
    1.46 +
    1.47  			Application.ApplicationExit += new EventHandler(OnApplicationExit);
    1.48  			//
    1.49              Application.EnableVisualStyles();
    1.50 @@ -25,6 +56,16 @@
    1.51              Application.Run(iMainForm);
    1.52          }
    1.53  
    1.54 +
    1.55 +
    1.56 +		static private bool IsRunAsAdministrator()
    1.57 +		{
    1.58 +		  var wi = WindowsIdentity.GetCurrent();
    1.59 +		  var wp = new WindowsPrincipal(wi);
    1.60 +
    1.61 +		  return wp.IsInRole(WindowsBuiltInRole.Administrator);
    1.62 +		}
    1.63 +
    1.64  		/// <summary>
    1.65  		/// Occurs after form closing.
    1.66  		/// </summary>