Server/Program.cs
author StephaneLenclud
Fri, 29 Jul 2016 14:33:47 +0200
changeset 228 6a84d8282226
parent 201 6213f42f1983
child 233 2b9541e54f7d
permissions -rw-r--r--
Adding test action button to edit action form.
Action.DoExecute now protected.
StephaneLenclud@123
     1
//
StephaneLenclud@123
     2
// Copyright (C) 2014-2015 Stéphane Lenclud.
StephaneLenclud@123
     3
//
StephaneLenclud@123
     4
// This file is part of SharpDisplayManager.
StephaneLenclud@123
     5
//
StephaneLenclud@123
     6
// SharpDisplayManager is free software: you can redistribute it and/or modify
StephaneLenclud@123
     7
// it under the terms of the GNU General Public License as published by
StephaneLenclud@123
     8
// the Free Software Foundation, either version 3 of the License, or
StephaneLenclud@123
     9
// (at your option) any later version.
StephaneLenclud@123
    10
//
StephaneLenclud@123
    11
// SharpDisplayManager is distributed in the hope that it will be useful,
StephaneLenclud@123
    12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
StephaneLenclud@123
    13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
StephaneLenclud@123
    14
// GNU General Public License for more details.
StephaneLenclud@123
    15
//
StephaneLenclud@123
    16
// You should have received a copy of the GNU General Public License
StephaneLenclud@123
    17
// along with SharpDisplayManager.  If not, see <http://www.gnu.org/licenses/>.
StephaneLenclud@123
    18
//
StephaneLenclud@123
    19
StephaneLenclud@123
    20
using System;
sl@0
    21
using System.Collections.Generic;
sl@0
    22
using System.Linq;
sl@0
    23
using System.Threading.Tasks;
sl@0
    24
using System.Windows.Forms;
sl@92
    25
using System.Security.Principal;
sl@92
    26
using System.Diagnostics;
sl@92
    27
using System.Reflection;
sl@0
    28
sl@0
    29
namespace SharpDisplayManager
sl@0
    30
{
sl@0
    31
    static class Program
sl@0
    32
    {
sl@31
    33
        //WARNING: This is assuming we have a single instance of our program.
sl@31
    34
        //That is what we want but we should enforce it somehow.
StephaneLenclud@226
    35
        public static FormMain iFormMain;
sl@0
    36
        /// <summary>
sl@0
    37
        /// The main entry point for the application.
sl@0
    38
        /// </summary>
sl@0
    39
        [STAThread]
sl@0
    40
        static void Main()
sl@92
    41
        {
sl@92
    42
StephaneLenclud@201
    43
            /*
sl@92
    44
			if (!IsRunAsAdministrator())
sl@92
    45
			{
sl@92
    46
				var processInfo = new ProcessStartInfo(Assembly.GetExecutingAssembly().CodeBase);
sl@92
    47
sl@92
    48
				// The following properties run the new process as administrator
sl@92
    49
				processInfo.UseShellExecute = true;
sl@92
    50
				processInfo.Verb = "runas";
sl@92
    51
sl@92
    52
				// Start the new process
sl@92
    53
				try
sl@92
    54
				{
sl@92
    55
					Process.Start(processInfo);
sl@92
    56
				}
sl@92
    57
				catch (Exception)
sl@92
    58
				{
sl@92
    59
					// The user did not allow the application to run as administrator
sl@92
    60
					MessageBox.Show("Sorry, this application must be run as Administrator.");
sl@92
    61
				}
sl@92
    62
sl@92
    63
				// Shut down the current process
sl@92
    64
				Application.Exit();
sl@92
    65
				return;
sl@92
    66
				//Application.Current.Shutdown();
sl@92
    67
			}*/
StephaneLenclud@201
    68
          
StephaneLenclud@201
    69
            Application.ApplicationExit += new EventHandler(OnApplicationExit);
sl@86
    70
			//
sl@0
    71
            Application.EnableVisualStyles();
sl@0
    72
            Application.SetCompatibleTextRenderingDefault(false);
StephaneLenclud@226
    73
            iFormMain = new FormMain();
StephaneLenclud@226
    74
            Application.Run(iFormMain);
sl@0
    75
        }
sl@86
    76
sl@92
    77
sl@92
    78
sl@92
    79
		static private bool IsRunAsAdministrator()
sl@92
    80
		{
sl@92
    81
		  var wi = WindowsIdentity.GetCurrent();
sl@92
    82
		  var wp = new WindowsPrincipal(wi);
sl@92
    83
sl@92
    84
		  return wp.IsInRole(WindowsBuiltInRole.Administrator);
sl@92
    85
		}
sl@92
    86
sl@86
    87
		/// <summary>
sl@86
    88
		/// Occurs after form closing.
sl@86
    89
		/// </summary>
sl@86
    90
		/// <param name="sender"></param>
sl@86
    91
		/// <param name="e"></param>
sl@86
    92
		static private void OnApplicationExit(object sender, EventArgs e)
sl@86
    93
		{
sl@86
    94
sl@86
    95
		}
sl@0
    96
    }
sl@0
    97
}