123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Security.Principal;
- using System.Windows.Forms;
- namespace UAS_DXFORM
- {
- static class Program
- {
- /// <summary>
- /// 应用程序的主入口点。
- /// </summary>
- [STAThread]
- static void Main()
- {
- WindowsIdentity identity = WindowsIdentity.GetCurrent();
- WindowsPrincipal principal = new WindowsPrincipal(identity);
- Application.EnableVisualStyles();
- Application.SetCompatibleTextRenderingDefault(false);
- 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 (principal.IsInRole(WindowsBuiltInRole.Administrator))
- Application.Run(new Form1());
- else
- {
- //创建启动对象
- System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
- // 设置运行文件
- startInfo.FileName = Application.ExecutablePath;
- //设置启动动作,确保以管理员身份运行
- startInfo.Verb = "runas";
- //如果不是管理员,则启动UAC
- System.Diagnostics.Process.Start(startInfo);
- }
- // Application.Run(new Form1());
- }
- }
- }
|