How to detect whether Vista UAC is enabled?

后端 未结 8 1312
渐次进展
渐次进展 2021-01-31 04:48

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?

8条回答
  •  故里飘歌
    2021-01-31 05:18

    This registry key should tell you:

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

    Value EnableLUA (DWORD)

    1 enabled / 0 or missing disabled

    But that assumes you have the rights to read it.

    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.

    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.

提交回复
热议问题