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

首頁 > 編程 > C# > 正文

C#中用管理員身份運行程序代碼實例

2020-01-24 02:08:33
字體:
來源:轉載
供稿:網友
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      {        //創建啟動對象         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();      }    }  }}  

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 济宁市| 年辖:市辖区| 禄劝| 隆林| 积石山| 许昌市| 鄂伦春自治旗| 玉屏| 蕉岭县| 惠州市| 永胜县| 哈尔滨市| 红桥区| 聂拉木县| 阿荣旗| 乐安县| 广饶县| 遂宁市| 金塔县| 北海市| 凯里市| 临泽县| 平昌县| 安达市| 江源县| 政和县| 新巴尔虎左旗| 齐齐哈尔市| 名山县| 滦平县| 巨鹿县| 普陀区| 定陶县| 砚山县| 丽江市| 靖西县| 石家庄市| 红原县| 杂多县| 杭锦旗| 东丽区|