如果用户使用提升的权限,如果没有UAC弹出运行无法检测 [英] Cannot detect if a user is running with elevated privileges, when no UAC popup

查看:256
本文介绍了如果用户使用提升的权限,如果没有UAC弹出运行无法检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发,需要检测用户是否正在作为提升的管理员C#应用程序。我试过<一href="http://stackoverflow.com/questions/1220213/c-detect-if-running-with-elevated-privileges">solution由史蒂芬建议。

I am developing a C# application that needs to detect whether the user is running as elevated administrator. I tried the solution suggested by Steven.

我查了5台机器的解决方案,并能正常工作的4人。

I checked the solution on 5 machines and it works fine on 4 of them.

有一个机器,从来没有显示UAC通知消息,即使我设置用户帐户控制,以始终通知我

There is one machine that never show the UAC notification message, even though I set the User Account Control to Always notify me.

在检查机器上的code,即使我选择以管理员身份运行,这是行不通的,该方法 IsProcessElevated 返回false。

When checking the code on that machine, even if I choose run as administrator, it doesn't work and the method IsProcessElevated returns false.

时的蹊跷的是特定的机器?

Is something wrong with that specific machine?

有没有办法来确定用户是否升高与否,在这样的平台?

Is there a way to determine whether a user is elevated or not, on that kind of platform?

推荐答案

研究我发现,从Windows 7和以确定用户是否升高管理员或没有你只需要检查以下后:

After a research I found out that from Windows 7 and on in order to determine whether a user is an elevated admin or not you just need to check the following:

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

(的code,检查令牌其余的情况下能够使用此选项失败) 我测试了code上的一些机器,它工作正常。

(The rest of the code that checks the Token can be used in case this option fails) I tested the code on some of the machines and it works ok.

我的应用程序只能在WIN7及以上所以这个解决方案是对我来说已经足够了。运行

my application runs only on win7 and above so this solution is good enough for me.

这篇关于如果用户使用提升的权限,如果没有UAC弹出运行无法检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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