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