|
@@ -1,21 +1,118 @@
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
+using System.IO;
|
|
|
using System.Linq;
|
|
|
+using System.Security.Principal;
|
|
|
+using System.Text;
|
|
|
using System.Windows.Forms;
|
|
|
+using System.Xml;
|
|
|
+using UAS_DeviceMonitor.Entity;
|
|
|
+using UAS_DeviceMonitor.PublicMethod;
|
|
|
|
|
|
namespace UAS_DeviceMonitor
|
|
|
{
|
|
|
static class Program
|
|
|
{
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
[STAThread]
|
|
|
static void Main()
|
|
|
{
|
|
|
- Application.EnableVisualStyles();
|
|
|
- Application.SetCompatibleTextRenderingDefault(false);
|
|
|
- Application.Run(new Main());
|
|
|
+ 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);
|
|
|
+
|
|
|
+ string sysdisc = Environment.GetEnvironmentVariable("windir").Substring(0, 1);
|
|
|
+ if (!Directory.Exists(SystemInf.LogFolder))
|
|
|
+ Directory.CreateDirectory(SystemInf.LogFolder);
|
|
|
+ FileStream fs = new FileStream(SystemInf.LogFolder + DateTime.Now.ToString("yyyy-MM-dd") + ".txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);
|
|
|
+ fs.Close();
|
|
|
+
|
|
|
+ if (!Directory.Exists(SystemInf.CacheFolder))
|
|
|
+ Directory.CreateDirectory(SystemInf.CacheFolder);
|
|
|
+ FileStream fcaches = new FileStream(SystemInf.CacheFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
|
|
|
+ fcaches.Close();
|
|
|
+
|
|
|
+ FileInfo info = new FileInfo(SystemInf.CacheFilePath);
|
|
|
+ if (info.Length == 0)
|
|
|
+ {
|
|
|
+ XmlDocument doc = new XmlDocument();
|
|
|
+
|
|
|
+ XmlNode node = doc.CreateXmlDeclaration("1.0", "utf-8", "");
|
|
|
+ doc.AppendChild(node);
|
|
|
+
|
|
|
+ XmlElement xeRoot = doc.CreateElement("cacheInfo");
|
|
|
+ doc.AppendChild(xeRoot);
|
|
|
+ doc.Save(SystemInf.CacheFilePath);
|
|
|
+ }
|
|
|
+
|
|
|
+ FileStream fas = new FileStream(SystemInf.CacheFolder + "lblprocess.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);
|
|
|
+ fas.Close();
|
|
|
+ if (principal.IsInRole(WindowsBuiltInRole.Administrator))
|
|
|
+ Application.Run(new Main());
|
|
|
+ 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.Message + " " + e.Exception.TargetSite + " " + 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());
|
|
|
+ LogManager.DoLog(str);
|
|
|
+ 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);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return sb.ToString();
|
|
|
}
|
|
|
}
|
|
|
}
|