C#管理员权限 - 检查 [英] C# administrator privilege - checking

查看:148
本文介绍了C#管理员权限 - 检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有一些类似的问题。 但是,我要检查的只有一件事。

I know that there are some similar questions. But I want to check only ONE thing.

我只是想知道,如果程序正在以管理员身份运行。 我要检查,因为我想编辑一些受保护的文件。 用户不必为管理员。我只是想知道,如果我的申请有权利编辑以管理员身份运行时可编辑的一些加密文件。

I only want to know if program is running as administrator. I want to check that because I want to edit some secured files. User don't have to be administrator. I only want to know if my application has rights to edit some secured files that are editable when running as Administrator.

推荐答案

这将返回一个布尔值有效

This will return a bool valid

using System.Security.Principal;

bool isElevated;
WindowsIdentity identity = WindowsIdentity.GetCurrent();
WindowsPrincipal principal = new WindowsPrincipal(identity);
isElevated = principal.IsInRole(WindowsBuiltInRole.Administrator);

这篇关于C#管理员权限 - 检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆