static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(true); //Start by looking for administrator privilege if (IsAdmin()) { //If administrator privilege is granted //close the current proceess if same process already opened. if (Environment.GetCommandLineArgs().Length > 1) { if (Environment.GetCommandLineArgs()[0] != "runAgainAsAdmin") { if (System.Diagnostics.Process.GetProcessesByName(System.IO.Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetEntryAssembly().Location)).Count() > 1) { System.Diagnostics.Process.GetCurrentProcess().Kill(); } } } // setup to custom font. SetupFont(); //add the app to startup applications. TaskingSchedule.RunOnStartup("MMB", Application.StartupPath + "\\" + System.AppDomain.CurrentDomain.FriendlyName); //run the app service ServiceAdapter.StartService("GUIAdapter", 10000); //setup global menuForm. menuForm = new MenuForm(); //check if this is the first time the app is opening on this computer. if (IsFirstOpening()) { ActAsFirstOpening(); } //setup the filtering system. FilteringSystem.Setup(); //start new menu form. Application.Run(menuForm); } else // { //If administrator privilege not granted, run again as administrator if (StartAgainAsAdmin()) { //By opening a new administrator-privileged process, close the current process. Application.ExitThread(); } else { //If the second attempt of opening as an administrator permission failed, Block the Internet (by the service) and close the current procees. ServiceAdapter.StartInternetBlocking(); MessageBox.Show("אפליקציה זו חייבת לרוץ כמנהל, האינטרנט מושבת.", "שגיאה", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification); Application.Exit(); } } }