1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- using System;
- using System.Text;
- using System.Windows.Forms;
- using System.Security.Principal;
- using UAS_LabelMachine.PublicMethod;
- using UAS_Labeling.PublicMethod;
- namespace UAS_LabelMachine
- {
- static class Program
- {
-
-
-
- [STAThread]
- static void Main(string[] Args)
- {
- try
- {
- WindowsIdentity identity = WindowsIdentity.GetCurrent();
- WindowsPrincipal principal = new WindowsPrincipal(identity);
-
- Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
-
- Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
-
- AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
- #region 应用程序的主入口点
- Application.EnableVisualStyles();
- Application.SetCompatibleTextRenderingDefault(false);
-
- GlobalEventsHandler g = new GlobalEventsHandler();
-
- Application.AddMessageFilter(g);
-
- if (principal.IsInRole(WindowsBuiltInRole.Administrator))
- {
- Application.Run(new Login());
- }
- else
- {
-
- System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
-
- startInfo.FileName = Application.ExecutablePath;
-
- startInfo.Verb = "runas";
-
- System.Diagnostics.Process.Start(startInfo);
-
- }
- #endregion
- }
- catch (Exception ex)
- {
- string str = GetExceptionMsg(ex, string.Empty);
- MessageBox.Show(str, "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
- {
- string str = GetExceptionMsg(e.Exception, e.ToString());
- LogManager.DoLog(e.Exception.StackTrace);
- MessageBox.Show(str, "操作异常", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- }
-
- static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
- {
- string str = GetExceptionMsg(e.ExceptionObject as Exception, e.ToString());
- MessageBox.Show(str, "操作异常", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- }
-
-
-
-
-
-
- static string GetExceptionMsg(Exception ex, string backStr)
- {
- StringBuilder sb = new StringBuilder();
- if (ex != null)
- {
- sb.AppendLine(ex.Message);
- LogManager.DoLog(ex.StackTrace);
- LogManager.DoLog(ex.TargetSite.ToString());
-
-
- }
- LogManager.DoLog(sb.ToString());
- return sb.ToString();
- }
- }
- }
|