Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

User exists in Local Admin Group 1

Status
Not open for further replies.

kadcore

Programmer
Nov 13, 2001
12
CA
With VB Script, Can I Check to see if a User is part of the local administrators group on the workstation?
 
yes, but its not a very good check if you want to determine if they have admin rights, unless something has changed lately you have to attempt to write a value to a root reg hive.

check the IsMember method

there should be posts in the KeyWord search on the subject
 
if its the local machine

Set User = GetObject("WinNT://" & strComputer & "/" & strUserName & ",user")
Set Group = GetObject("WinNT://" & strComputer & "/Administrators,group")
Msgbox Group.IsMember(User.ADsPath)

it be faster to just get the User object and iterate through the groups

Set User = GetObject("WinNT://" & strComputer & "/" & strUserName & ",user")
For Each aGroup In User.Groups
If LCase(aGroup.Name) = "administrators" Then
Msgbox "yes they are"
End If
Next


or, it might be quicker to just use the group

Set Group = GetObject("WinNT://" & strComputer & "/Administrators,group")
For Each aMember In Group.Members
If aMember.Name = strUserName Then
Msgbox "they are"
End If
Next

all depends on your taste and if you prefer to only bind to one object, but i think i stretch the point
 
Thanks for the response and solution mrmovie
 
What if you wanted to find a AD domain user on a computer who's a member of multiple local group accounts?
 
you have to bind to the local computer using something the WinNT provider, loop through all the local groups checking if the user is a member of one of them, then act on it if required
 
I did that and was able to display all local groups that a domain user belongs to. How do you display domain group users within my local group. Here's my script:

Set oWshNet = CreateObject("WScript.Network")
StrUserID = InputBox("Enter UserID")
Const FOR_READING = 1
StrFilename = "c:\scripts\host.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFilename, FOR_READING)
Do Until objFile.AtEndofStream
StrComputer = objFile.ReadLine
Wscript.Echo "Server:" & StrComputer
Wscript.Echo ""
Set colGroups = GetObject("WinNT://" & strComputer & "")
colGroups.Filter = Array("group")
For Each oGroup In colGroups
For Each oUser in oGroup.Members
' Check if user is a local user
If InStr(1, oUser.ADsPath, "/" & sComputer & "/", vbTextCompare) > 0 Then
If oUser.Name = StrUserID Then
Wscript.Echo vbTab & "Local Group:" & oGroup.Name
End If
End If
Next
Next
Loop
objFile.Close
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top