如何检测是否启用了 Vista UAC? [英] How to detect whether Vista UAC is enabled?

查看:23
本文介绍了如何检测是否启用了 Vista UAC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要我的应用程序根据是否启用 Vista UAC 来表现不同.我的应用程序如何检测用户计算机上的 UAC 状态?

I need my application to behave differently depending on whether Vista UAC is enabled or not. How can my application detect the state of UAC on the user's computer?

推荐答案

这个注册表项应该告诉你:

This registry key should tell you:

HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System

EnableLUA (DWORD)

1 启用/0 或缺失 禁用

1 enabled / 0 or missing disabled

但前提是您有权阅读它.

But that assumes you have the rights to read it.

您可以尝试以编程方式读取用户的令牌并猜测它是否是启用了 UAC 的管理员运行(请参阅 此处).并非万无一失,但可能会奏效.

Programmatically you can try to read the user's token and guess if it's an admin running with UAC enabled (see here). Not foolproof, but it may work.

这里的问题更多是你为什么需要知道"——它与答案有关.确实,没有 API,因为从操作系统行为的角度来看,重要的是用户是否是管理员 - 他们如何选择以管理员身份保护自己是他们的问题.

The issue here is more of a "why do you need to know" - it has bearing on the answer. Really, there is no API because from a OS behavior point of view, what matters is if the user is an administrator or not - how they choose to protect themselves as admin is their problem.

这篇关于如何检测是否启用了 Vista UAC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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