通过c#管理员权限检查的普通用户 [英] normal user with administrator privileges checker by c#
本文介绍了通过c#管理员权限检查的普通用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的所有
i我正在使用此代码让应用程序知道用户是否以管理员或普通用户身份登录
dear all
i am using this code to let the application know if the user logged is as administrator or normal user
WindowsIdentity windowsIdentity = WindowsIdentity.GetCurrent();
//To show user name use
//windowsIdentity.Name.ToString()
WindowsPrincipal windowsPrincipal = new WindowsPrincipal(windowsIdentity);
//To check if user is administrator use IsInRole method
// MessageBox.Show("Is Adminisitrator = " + windowsPrincipal.IsInRole(WindowsBuiltInRole.Administrator));
if (windowsPrincipal.IsInRole(WindowsBuiltInRole.Administrator) == true)
{
admini = "1";//admisnistrator
}
else
{
admini = "2";//non-admisnistrator
}
它运作良好,但问题是当普通用户有 管理员的特权
此代码检测到他不是管理员而他有权作为管理员工作。
i希望有权使用管理员的普通用户正确使用我的应用程序但我不能
任何想法
it is working well but the problem is when a normal user has the privileges of administrator
this code detects that he is not administrator while he has the privileges to work as admin.
i want the normal user that has the privileges to work as admin to use my application correctly but i can not
any idea
推荐答案
你好b $ b
只要您使用的是Windows 7或更高版本,这应该可以正常工作。类似问题的一些答案表明它可能与UAC有关。查看以下文章 - 也许你会找到解决问题的方法。
link1:http://stackoverflow.com/questions/11955302/cannot-detect-if-a- user-is-running-with-elevated-privileges-when-no-uac-popup [ ^ ]
link2: http://stackoverflow.com / questions / 13934946 / detect-if-running-with-elevated-privileges-domain-administrator-accounts-inclu [ ^ ]
link3: http://stackoverflow.com/questions/1220213/detect-if-running-with-elevated-privileges [ ^ ]
Hi
This should work as long as you are using windows 7 or later. Some of the answers to similiar qustions suggest it might have something to do with UAC. Check out the following articles - maybe you will find a solution to your problem.
link1: http://stackoverflow.com/questions/11955302/cannot-detect-if-a-user-is-running-with-elevated-privileges-when-no-uac-popup[^]
link2: http://stackoverflow.com/questions/13934946/detect-if-running-with-elevated-privileges-domain-administrator-accounts-inclu[^]
link3: http://stackoverflow.com/questions/1220213/detect-if-running-with-elevated-privileges[^]
这篇关于通过c#管理员权限检查的普通用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文