国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設計 > 正文

C#以管理員身份運行程序

2019-11-17 02:43:52
字體:
來源:轉載
供稿:網友

C#以管理員身份運行程序

代碼:

using System;using System.Collections.Generic;using System.Linq;using System.Windows.Forms;namespace MyWebBrowser{    static class PRogram    {        /// <summary>        /// 應用程序的主入口點。        /// </summary>        [STAThread]        static void Main()        {            //獲得當前登錄的Windows用戶標示             System.Security.Principal.WindowsIdentity identity = System.Security.Principal.WindowsIdentity.GetCurrent();            System.Security.Principal.WindowsPrincipal principal = new System.Security.Principal.WindowsPrincipal(identity);            //判斷當前登錄用戶是否為管理員             if (principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator))            {                //如果是管理員,則直接運行                 application.EnableVisualStyles();                Application.SetCompatibleTextRenderingDefault(false);                Application.Run(new Form1());            }            else            {                //創(chuàng)建啟動對象                 System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();                //設置運行文件                 startInfo.FileName = System.Windows.Forms.Application.ExecutablePath;                //設置啟動動作,確保以管理員身份運行                 startInfo.Verb = "runas";                //如果不是管理員,則啟動UAC                 System.Diagnostics.Process.Start(startInfo);                //退出                 System.Windows.Forms.Application.Exit();            }        }    }}
View Code


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 康马县| 苗栗县| 浏阳市| 汉中市| 牡丹江市| 凉山| 抚远县| 临城县| 兰州市| 富民县| 尚志市| 自治县| 万州区| 博乐市| 乐平市| 平南县| 囊谦县| 西乌珠穆沁旗| 潢川县| 普安县| 勐海县| 南部县| 泸西县| 东阿县| 乌拉特中旗| 万州区| 绍兴市| 原平市| 合作市| 北海市| 邵武市| 霍林郭勒市| 山西省| 乌苏市| 辽阳市| 杭锦旗| 云和县| 临洮县| 江安县| 灵璧县| 浮山县|