标签:style blog color ar sp div art on log
// 检查是否是管理员身份 private void CheckAdministrator() { try { var wi = WindowsIdentity.GetCurrent(); var wp = new WindowsPrincipal(wi); bool runAsAdmin = wp.IsInRole(WindowsBuiltInRole.Administrator); if (!runAsAdmin) { var processInfo = new ProcessStartInfo(Assembly.GetExecutingAssembly().CodeBase) { UseShellExecute = true, Verb = "runas" }; Process.Start(processInfo); Current.Shutdown(); } } catch { Current.Shutdown(); } } //配置启动项 protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); CheckAdministrator(); }
标签:style blog color ar sp div art on log
原文地址:http://www.cnblogs.com/gaobing/p/4022707.html