Connecting Tech Pros Worldwide Forums | Help | Site Map

Programmatically detect if UAC turned on?

=?Utf-8?B?Um9iS2lubmV5MQ==?=
Guest
 
Posts: n/a
#1: Feb 6 '07
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

Michael Nemtsev
Guest
 
Posts: n/a
#2: Feb 7 '07

re: Programmatically detect if UAC turned on?


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

RThis could be REAL simple, but I cannot find any info on it anywhere
Rafter 2 hours of searching.
R>
RHow can I programmatically determine if the UAC is turned in Vista
Rusing 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


=?Utf-8?B?Um9iS2lubmV5MQ==?=
Guest
 
Posts: n/a
#3: Feb 7 '07

re: Programmatically detect if UAC turned on?


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

"Michael Nemtsev" wrote:
Quote:
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
>
RThis could be REAL simple, but I cannot find any info on it anywhere
Rafter 2 hours of searching.
R>
RHow can I programmatically determine if the UAC is turned in Vista
Rusing 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
>
>
>
Willy Denoyette [MVP]
Guest
 
Posts: n/a
#4: Feb 7 '07

re: Programmatically detect if UAC turned on?


"RobKinney1" <RobKinney1@discussions.microsoft.comwrote in message
news:547640CA-F017-4F48-ACF9-E7ADA8A9E3A1@microsoft.com...
Quote:
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.

Closed Thread