Originally Posted By: Roger
Still easier in PowerShell:
Code:
([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(
        [Security.Principal.WindowsBuiltInRole] "Administrator")



I haven't looked back at that one for a while, but I seem to recall that the method you list there didn't work the way I needed it to work. I might be remembering it wrong, but here was the issue I encountered...

- On Windows 7 with UAC disabled, simply checking to see if your program was running as a member of the builtin administrators role was enough.

- On Windows 8 and later, even if you disable UAC, running a program under the builtin administrator account still was not enough. For example if you run a DOS batch file or any EXE, it is, by default, not set to have administrator-level privileges even if you are already logged in as a member of the administrators group, so you will still get permissions errors. The only way around it is if you explicity right-click and select "run as administrator" on the batch file or EXE. (Or if the EXE is written to self-elevate.)

I seem to recall that the method you quote there won't accurately determine the latter thing. (As I said I could be remembering it wrong.)
_________________________
Tony Fabris