Notifications
Clear all

[Closed] Determine whether user is Administrator

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

6 Replies

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

I had to remove the ‘s’ from the end of ‘admin.administratrors’ to get it to work, but it certainly does the trick.

Thanks!

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

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.

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?

Yes, Win 7 is the same. And, yes, it’s a pain.