StephaneLenclud@123: //
StephaneLenclud@123: // Copyright (C) 2014-2015 Stéphane Lenclud.
StephaneLenclud@123: //
StephaneLenclud@123: // This file is part of SharpDisplayManager.
StephaneLenclud@123: //
StephaneLenclud@123: // SharpDisplayManager is free software: you can redistribute it and/or modify
StephaneLenclud@123: // it under the terms of the GNU General Public License as published by
StephaneLenclud@123: // the Free Software Foundation, either version 3 of the License, or
StephaneLenclud@123: // (at your option) any later version.
StephaneLenclud@123: //
StephaneLenclud@123: // SharpDisplayManager is distributed in the hope that it will be useful,
StephaneLenclud@123: // but WITHOUT ANY WARRANTY; without even the implied warranty of
StephaneLenclud@123: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
StephaneLenclud@123: // GNU General Public License for more details.
StephaneLenclud@123: //
StephaneLenclud@123: // You should have received a copy of the GNU General Public License
StephaneLenclud@123: // along with SharpDisplayManager. If not, see .
StephaneLenclud@123: //
StephaneLenclud@123:
StephaneLenclud@123: 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: }