How to detect whether Vista UAC is enabled?

后端 未结 8 1281
渐次进展
渐次进展 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:26

    This post has sample code in C# to test if UAC is on and if the current app has been given elevated rights. You can download the code and interpret as needed. Also linked there is a sample that shows the same in C++

    http://www.itwriting.com/blog/198-c-code-to-detect-uac-elevation-on-vista.html

    The code in that post does not just read from the registry. If UAC is enabled, chances are you may not have rights to read that from the registry.

    0 讨论(0)
  • 2021-01-31 05:28

    This post is rather ancient, but I wanted to comment on the "why do you need to know" and "check token membership" bits.

    The fact is that Microsoft's very own documentation says that "If User Account Control has been turned off and a Standard user attempts to perform a task that requires elevation" we should provide an error instead of showing buttons and/or links with the UAC shield that attempt elevation. See http://msdn.microsoft.com/en-us/library/windows/desktop/aa511445.aspx towards the bottom for the details.

    How are we do to this without a way of checking whether UAC is enabled?

    Perhaps checking whether the user is running with admin privileges is the right thing to do in this instance, but who knows? The guidance that Microsoft gives is, at best, iffy, if not just downright confusing.

    0 讨论(0)
提交回复
热议问题