Programmatically detect if UAC turned on?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

This could be REAL simple, but I cannot find any info on it anywhere after 2
hours of searching.

How can I programmatically determine if the UAC is turned in Vista using C#?

I need to detect this because for some reason Office automation (creating a
new document) is not creating it relative to the VirtualStore when UAC is
turned on... therefore I have to know when to build up the VirtualStore paths.

Thanks,

Rob
 
Hello RobKinney1,

You need to request info from GetTokenInformation() WinAPI function

See the sample of elevating UAC there http://www.codeproject.com/useritems/VistaElevator.asp

R> This could be REAL simple, but I cannot find any info on it anywhere
R> after 2 hours of searching.
R>
R> How can I programmatically determine if the UAC is turned in Vista
R> using C#?


---
WBR, Michael Nemtsev [C# MVP]. Blog: http://spaces.live.com/laflour
team blog: http://devkids.blogspot.com/

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo
 
Thanks Michael. Following your advice eventually led to refined solution of
importing the following:

[DllImport("shell32.dll", EntryPoint = "#680", CharSet =
CharSet.Unicode)]
public static extern bool IsUserAnAdmin();

(I can't remember where I got this, but it was on a page that discussed the
GetTokenInformation() function)

So I tested on my computer with UAC turned on, and it returned False, then
without it on and it returned true.

Thanks for pointing me in the right direction!

Rob
 
RobKinney1 said:
Thanks Michael. Following your advice eventually led to refined solution of
importing the following:

[DllImport("shell32.dll", EntryPoint = "#680", CharSet =
CharSet.Unicode)]
public static extern bool IsUserAnAdmin();

(I can't remember where I got this, but it was on a page that discussed the
GetTokenInformation() function)

So I tested on my computer with UAC turned on, and it returned False, then
without it on and it returned true.

Thanks for pointing me in the right direction!

Note that this doesn't answer the question whether UAC is turned on, it only tells you you
are an administrator or not.

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top