Program.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using CefSharp;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Security.Principal;
  6. using System.Windows.Forms;
  7. namespace UAS_Web
  8. {
  9. static class Program
  10. {
  11. /// <summary>
  12. /// 应用程序的主入口点。
  13. /// </summary>
  14. [STAThread]
  15. static void Main()
  16. {
  17. try
  18. {
  19. WindowsIdentity identity = WindowsIdentity.GetCurrent();
  20. WindowsPrincipal principal = new WindowsPrincipal(identity);
  21. //设置应用程序处理异常方式:ThreadException处理
  22. Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
  23. #region 应用程序的主入口点
  24. var setting = new CefSettings();
  25. setting.CefCommandLineArgs.Add("disable-gpu", "1");
  26. Cef.Initialize(setting);
  27. Application.EnableVisualStyles();
  28. Application.SetCompatibleTextRenderingDefault(false);
  29. //如果是管理员的身份
  30. if (principal.IsInRole(WindowsBuiltInRole.Administrator))
  31. {
  32. Application.Run(new Browser());
  33. }
  34. else
  35. {
  36. //创建启动对象
  37. System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
  38. // 设置运行文件
  39. startInfo.FileName = Application.ExecutablePath;
  40. //设置启动动作,确保以管理员身份运行
  41. startInfo.Verb = "runas";
  42. //如果不是管理员,则启动UAC
  43. System.Diagnostics.Process.Start(startInfo);
  44. //退出 System.Windows.Forms.Application.Exit();
  45. }
  46. #endregion
  47. }
  48. catch (Exception)
  49. {
  50. }
  51. }
  52. }
  53. }