PDA

View Full Version : Determine whether user is Administrator


Rorschach
02-03-2010, 10:21 AM
I assume this will have to be done through dotnet, but does anyone have any solutions for checking whether the current user has administrator priviliges?

Thanks

instinct-vfx
02-03-2010, 11:02 AM
Hey there, here's a dotnet example:


-- create a WindowsIdentity Instance
wi = dotnetclass "System.Security.Principal.WindowsIdentity"
-- get the Current Itentity (the user logged in)
CurrentIdentity = wi.GetCurrent()
-- just as an example, get the username
print CurrentIdentity.Name
-- create a "BuiltInRole" instance to check for Administrators
admin = dotnetclass "System.Security.Principal.WindowsBuiltInRole"
-- create a Principal object with the current identity
wp = dotnetobject "System.Security.Principal.WindowsPrincipal" CurrentIdentity
-- check if the principal is part of the administrators role
if (wp.isInRole admin.administrators)==true then print "Yay, an Admin"


refer to msdn for more info on these classes

Kind Regards,
Thorsten

Rorschach
02-03-2010, 11:24 AM
I had to remove the 's' from the end of 'admin.administratrors' to get it to work, but it certainly does the trick.

Thanks!

Rorschach
02-25-2010, 11:00 AM
This doesn't seem to work in Vista... returns false even if run as administrator. Any thoughts?

edit: sorry, seems even if logged in as admin programs aren't defaultly run as admin in vista? Works if I chose run as admin

PEN
02-25-2010, 11:55 AM
Vista figures your a complete idiot and you really didn't want to sign in as administrator so you have to tell it again and again and again.

Rorschach
02-25-2010, 12:07 PM
I've avoided Vista till now, but my god, what a mess.

UAC is insane... does anyone actually leave that on? Talk about over protective. Does windows 7 behauve the same?

JHaywood
02-25-2010, 05:56 PM
Yes, Win 7 is the same. And, yes, it's a pain.

CGTalk Moderation
02-25-2010, 05:56 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.