static void Main(string[] args) { using (Mutex m = new Mutex(false, "Global\\" + appGuid)) { //MessageBox.Show("Test 1.0.0.2"); SCUtility.SystemEventLog("Start BC System!!", EventLogEntryType.Information); //檢查是否同名Mutex已存在(表示另一份程式正在執行) //if (!m.WaitOne(0, false)) //{ // Console.WriteLine("Only one instance is allowed!"); // SCUtility.SystemEventLog("Can Not Execute Multiple BC System!!", EventLogEntryType.Warning); // var confirmResult = MessageBox.Show("Can Not Execute Multiple BC System!!", // "Confirm Exit BC System!!", MessageBoxButtons.OK, MessageBoxIcon.Warning); // return; //} //////檢查是否有重複開啟BC System //System.Diagnostics.Process crProcess = System.Diagnostics.Process.GetCurrentProcess(); //System.Diagnostics.Process[] myProcess = System.Diagnostics.Process.GetProcessesByName(crProcess.ProcessName); //if (myProcess.Length > 1) //{ // SCUtility.SystemEventLog("Can Not Execute Multiple BC System!!", EventLogEntryType.Warning); // var confirmResult = MessageBox.Show("Can Not Execute Multiple BC System!", // "Confirm Exit BC System!", MessageBoxButtons.OK, MessageBoxIcon.Warning); // return; //} string bcName = Environment.GetEnvironmentVariable("BCNAME"); //Console.WriteLine("BCNAME:{0}", bcName); string argStr = SCUtility.stringListToString(" ", args.ToList()); if (BCFUtility.isEmpty(argStr)) { bcName = "OHS100"; args = new string[] { bcName }; argStr = bcName; } else { bcName = args[0]; } copyConfig(bcName); ConfigSystem.Install(); //var wi = WindowsIdentity.GetCurrent(); //var wp = new WindowsPrincipal(wi); //bool runAsAdmin = wp.IsInRole(WindowsBuiltInRole.Administrator); //if (!runAsAdmin) //{ // Console.WriteLine("Try Change Run As Admin."); // MessageBox.Show("Try Change Run As Admin."); // var processInfo = new ProcessStartInfo(Assembly.GetExecutingAssembly().CodeBase); // processInfo.UseShellExecute = true; // processInfo.Verb = "runas"; // processInfo.Arguments = argStr; // // Start the new process // try // { // Process.Start(processInfo); // } // catch (Exception) // { // Console.WriteLine("Sorry, can't to start " + // "this program with administrator rights!"); // MessageBox.Show("Sorry, can't to start " + // "this application with administrator rights!"); // } // return; //} AppDomain currentDomain = AppDomain.CurrentDomain; //A0.12 currentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyHandler); //A0.12 Application.ThreadException += Application_ThreadException; Thread.CurrentThread.CurrentUICulture = Properties.Settings.Default.UICulture; //Localization.BuildMultiLanguageResources(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new BCMainForm(args[0], args[1])); SCUtility.SystemEventLog("Close BC System!!", EventLogEntryType.Information); Application.ExitThread(); //crProcess.Kill(); } }