sl@0: using System; sl@0: using System.Collections.Generic; sl@0: using System.Linq; sl@0: using System.Threading.Tasks; sl@0: using System.Windows.Forms; sl@92: using System.Security.Principal; sl@92: using System.Diagnostics; sl@92: using System.Reflection; sl@0: sl@0: namespace SharpDisplayManager sl@0: { sl@0: static class Program sl@0: { sl@31: //WARNING: This is assuming we have a single instance of our program. sl@31: //That is what we want but we should enforce it somehow. sl@17: public static MainForm iMainForm; sl@0: /// sl@0: /// The main entry point for the application. sl@0: /// sl@0: [STAThread] sl@0: static void Main() sl@92: { sl@92: sl@92: /* sl@92: if (!IsRunAsAdministrator()) sl@92: { sl@92: var processInfo = new ProcessStartInfo(Assembly.GetExecutingAssembly().CodeBase); sl@92: sl@92: // The following properties run the new process as administrator sl@92: processInfo.UseShellExecute = true; sl@92: processInfo.Verb = "runas"; sl@92: sl@92: // Start the new process sl@92: try sl@92: { sl@92: Process.Start(processInfo); sl@92: } sl@92: catch (Exception) sl@92: { sl@92: // The user did not allow the application to run as administrator sl@92: MessageBox.Show("Sorry, this application must be run as Administrator."); sl@92: } sl@92: sl@92: // Shut down the current process sl@92: Application.Exit(); sl@92: return; sl@92: //Application.Current.Shutdown(); sl@92: }*/ sl@92: sl@92: sl@86: Application.ApplicationExit += new EventHandler(OnApplicationExit); sl@86: // sl@0: Application.EnableVisualStyles(); sl@0: Application.SetCompatibleTextRenderingDefault(false); sl@17: iMainForm = new MainForm(); sl@17: Application.Run(iMainForm); sl@0: } sl@86: sl@92: sl@92: sl@92: static private bool IsRunAsAdministrator() sl@92: { sl@92: var wi = WindowsIdentity.GetCurrent(); sl@92: var wp = new WindowsPrincipal(wi); sl@92: sl@92: return wp.IsInRole(WindowsBuiltInRole.Administrator); sl@92: } sl@92: sl@86: /// sl@86: /// Occurs after form closing. sl@86: /// sl@86: /// sl@86: /// sl@86: static private void OnApplicationExit(object sender, EventArgs e) sl@86: { sl@86: sl@86: } sl@0: } sl@0: }