Events can now be instantiated.
Action editor is now a generic object editor.
2 // Copyright (C) 2014-2015 Stéphane Lenclud.
4 // This file is part of SharpDisplayManager.
6 // SharpDisplayManager is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
11 // SharpDisplayManager is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with SharpDisplayManager. If not, see <http://www.gnu.org/licenses/>.
21 using System.Collections.Generic;
23 using System.Threading.Tasks;
24 using System.Windows.Forms;
25 using System.Security.Principal;
26 using System.Diagnostics;
27 using System.Reflection;
29 namespace SharpDisplayManager
33 //WARNING: This is assuming we have a single instance of our program.
34 //That is what we want but we should enforce it somehow.
35 public static FormMain iFormMain;
37 /// The main entry point for the application.
44 if (!IsRunAsAdministrator())
46 var processInfo = new ProcessStartInfo(Assembly.GetExecutingAssembly().CodeBase);
48 // The following properties run the new process as administrator
49 processInfo.UseShellExecute = true;
50 processInfo.Verb = "runas";
52 // Start the new process
55 Process.Start(processInfo);
59 // The user did not allow the application to run as administrator
60 MessageBox.Show("Sorry, this application must be run as Administrator.");
63 // Shut down the current process
66 //Application.Current.Shutdown();
69 Application.ApplicationExit += new EventHandler(OnApplicationExit);
71 Application.EnableVisualStyles();
72 Application.SetCompatibleTextRenderingDefault(false);
73 iFormMain = new FormMain();
74 Application.Run(iFormMain);
79 static private bool IsRunAsAdministrator()
81 var wi = WindowsIdentity.GetCurrent();
82 var wp = new WindowsPrincipal(wi);
84 return wp.IsInRole(WindowsBuiltInRole.Administrator);
88 /// Occurs after form closing.
90 /// <param name="sender"></param>
91 /// <param name="e"></param>
92 static private void OnApplicationExit(object sender, EventArgs e)