当前位置:网站首页>C# 是否管理员权限运行运行软件
C# 是否管理员权限运行运行软件
2022-04-22 12:54:00 【IT技术猿猴】
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace administrator
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
if(!IsAdministrator())
{
return;
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
public static bool IsAdministrator()
{
WindowsIdentity current = WindowsIdentity.GetCurrent();
WindowsPrincipal windowsPrincipal = new WindowsPrincipal(current);
//WindowsBuiltInRole可以枚举出很多权限,例如系统用户、User、Guest等等
return windowsPrincipal.IsInRole(WindowsBuiltInRole.Administrator);
}
}
}
版权声明
本文为[IT技术猿猴]所创,转载请带上原文链接,感谢
https://blog.csdn.net/baobingji/article/details/124333914
边栏推荐
- Today's sleep quality record 76 points
- VNC连接Too many security failures
- H5<canvas>标签+原生JS 自制一个简易画图工具
- TypeError: connection. connect is not a function
- Share some practical skills accumulated in a recent mobile terminal project
- The R language uses the treemap function in the treemap package to visualize the treemap graph: treemap displays the hierarchical data as a group of nested rectangles, customized label color, label ba
- Write your own compiler: build a syntax tree through syntax compilation and realize intermediate code generation
- 396. 旋转函数
- Thread related issues
- OpenCV项目1-OCR识别
猜你喜欢

分享一下自己最近写项目遇到的小问题

尝试opencv裂缝检测

matlab 桥梁跨径组合问题GUI图形界面完成

Daily question series: common substring calculation

Partagez quelques conseils pratiques que vous avez accumulés sur un projet mobile récemment écrit

智慧文旅逐渐数字化,vr全景推动文旅一体化发展

396. Fonction de rotation

11. Container with the most water

诺瓦星云更新招股书,继续上市进程,“学术派”的步步为盈?

今日睡眠质量记录76分
随机推荐
Simple deployment of microservices
Ros2 learning notes (10) learn the workspace of ros2 from turnlesim
OpenCV项目1-OCR识别
Generation process of executable file
智能家居的新想法(2022)
JS随机颜色
Secondary development of ABAQUS RSG plug-in (II)
R language ggplot2 visualization: ggplot2 visualization moves the legend of the image to the inside of the image and customizes the location of the legend
The difference between let and VaR, several classic small questions
VR panorama truly restores the driving school environment, and VR live shows the hard power of the driving school
Solve the problem that CMD commands cannot be executed continuously
VNC连接Too many security failures
分享一下自己最近写的一个移动端项目积累的一些实用技巧
Express Can‘t set headers after they are sent.问题
R语言ggplot2可视化固定图像的纵横比aspect ratio实战:coord_fixed()函数
VNC connection to too many security failures
The ABAQUS model of standardized steel box girder is established, and the plug-in of RSG is used for secondary development
17. 电话号码的字母组合
396. 旋轉函數
男女配对问题