Loading...
 

Users and Groups



Adding a User to a Local Group

Adds a user (kenmyer) to the local Administrators group on a computer named MyComputer.
strComputer = "MyComputer"
Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators,group")
Set objUser = GetObject("WinNT://" & strComputer & "/kenmyer,user")
objGroup.Add(objUser.ADsPath)Creating a Local Group on a Computer

Create a local group

Creates a local group named FinanceUsers on a computer named MyComputer.
strComputer = "MyComputer"
Set colAccounts = GetObject("WinNT://" & strComputer & "")
Set objUser = colAccounts.Create("group", "FinanceUsers")
objUser.SetInfoDeleting a Local Group

Delete a local group

Deletes a local group named FinanceUsers from a computer named MyComputer.
strComputer = "MyComputer"
Set objComputer = GetObject("WinNT://" & strComputer & "")
objComputer.Delete "group", "FinanceUsers"Deleting a User from a Local Group

Remove a user from a group

Removes kenmyer from the local Administrators group on a computer named MyComputer.
strComputer = "MyComputer"
Set objGroup = GetObject("WinNT://" & strComputer & "/Adminstrators,group")
Set objUser = GetObject("WinNT://" & strComputer & "/kenmyer,user")
 
objGroup.Remove(objUser.ADsPath)Enumerating Local Groups and Their Members

List local groups

Returns a list of local groups (and their members) found on a computer named atl-win2k-01.
strComputer = "atl-win2k-01"
Set colGroups = GetObject("WinNT://" & strComputer & "")
colGroups.Filter = Array("group")
For Each objGroup In colGroups
    Wscript.Echo objGroup.Name 
    For Each objUser in objGroup.Members
        Wscript.Echo vbTab & objUser.Name
    Next
Next

Listing All the Local Groups a User Belongs To

Returns a list of all the local groups on the computer atl-win2k-01 that a user named kenmyer belongs to.
strComputer = "atl-win2k-01"
Set colGroups = GetObject("WinNT://" & strComputer & "")
colGroups.Filter = Array("group")
For Each objGroup In colGroups
    For Each objUser in objGroup.Members
        If objUser.name = "kenmyer" Then
            Wscript.Echo objGroup.Name
        End If
    Next
Next

Show php error messages