Server/Program.cs
author StephaneLenclud
Wed, 04 Feb 2015 15:48:08 +0100
changeset 103 14f6c8d21ec1
parent 86 829dd13b1048
child 123 0df386e37e29
permissions -rw-r--r--
Setting layout size according to display.
Added comments.
     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Threading.Tasks;
     5 using System.Windows.Forms;
     6 using System.Security.Principal;
     7 using System.Diagnostics;
     8 using System.Reflection;
     9 
    10 namespace SharpDisplayManager
    11 {
    12     static class Program
    13     {
    14         //WARNING: This is assuming we have a single instance of our program.
    15         //That is what we want but we should enforce it somehow.
    16         public static MainForm iMainForm;
    17         /// <summary>
    18         /// The main entry point for the application.
    19         /// </summary>
    20         [STAThread]
    21         static void Main()
    22         {
    23 
    24 			/*
    25 			if (!IsRunAsAdministrator())
    26 			{
    27 				var processInfo = new ProcessStartInfo(Assembly.GetExecutingAssembly().CodeBase);
    28 
    29 				// The following properties run the new process as administrator
    30 				processInfo.UseShellExecute = true;
    31 				processInfo.Verb = "runas";
    32 
    33 				// Start the new process
    34 				try
    35 				{
    36 					Process.Start(processInfo);
    37 				}
    38 				catch (Exception)
    39 				{
    40 					// The user did not allow the application to run as administrator
    41 					MessageBox.Show("Sorry, this application must be run as Administrator.");
    42 				}
    43 
    44 				// Shut down the current process
    45 				Application.Exit();
    46 				return;
    47 				//Application.Current.Shutdown();
    48 			}*/
    49 
    50 
    51 			Application.ApplicationExit += new EventHandler(OnApplicationExit);
    52 			//
    53             Application.EnableVisualStyles();
    54             Application.SetCompatibleTextRenderingDefault(false);
    55             iMainForm = new MainForm();
    56             Application.Run(iMainForm);
    57         }
    58 
    59 
    60 
    61 		static private bool IsRunAsAdministrator()
    62 		{
    63 		  var wi = WindowsIdentity.GetCurrent();
    64 		  var wp = new WindowsPrincipal(wi);
    65 
    66 		  return wp.IsInRole(WindowsBuiltInRole.Administrator);
    67 		}
    68 
    69 		/// <summary>
    70 		/// Occurs after form closing.
    71 		/// </summary>
    72 		/// <param name="sender"></param>
    73 		/// <param name="e"></param>
    74 		static private void OnApplicationExit(object sender, EventArgs e)
    75 		{
    76 
    77 		}
    78     }
    79 }