I need to check whether the user executing the script has administrative privileges on the machine.
I have specified the user executing the script because the script could have been executed with a user other than the logged on using something similar to "Runas".
@Javier: Both solutions work in a PC with an English version of Windows installed but not if the installed is in different language. This is because the Administrators group doesn't exist, the name is different for instance in Spanish. I need the solution to work in all configurations.
What about checking for "\\computername\Admin$\system32"?
By doing this you break scenarios where the user has the required privs for your script but does not belong to Administrators. Instead of checking for group membership, check for the specific abilities you require.
Using "localhost" instead of the real hostname increases the script runtime about 10x!
My final code is:
This script returns exit code 0 if the current user is a local admin.
Usage: cscript.exe get_admin_status.vbs
I know this thread is very old and marked answered but the answer isn't really giving what the OP asked about.
For anyone else searching and finding this page, here is an alternative that does report based on rights not group membership so Runas Administrator shows admin rights as True.
This article has a nice chunk of code on how to enumerate the members of a group (copied here for convenience and edited to not use email address):
You can then write a function to see if a user is in the list...
...and call it like this:
User may be not in local administrator group. For example - domain admins. UAC usually blocks admin access to registry, shares e.t.c. even for administrators(onl y manual "run as admin" gets right)...
Here is my crazy way: