Platform SDK: Active Directory, ADSI, and Directory Services |
The simplest listing of users to generate is a list of all the users in a given domain or on a particular machine. The following code lists the users on the computer localmachine:
Dim myComputer Dim member Set myComputer = GetObject("WinNT://localmachine,computer") myComputer.Filter = Array("user") For Each member In myComputer WScript.Echo member.Name Next
Notice the use of the Filter property of the computer object to constrain the enumeration of myComputer to return only users.
Listing the users who have access to a server, but cannot log on locally, can be done by binding to the Users object on a particular computer. The Users object exists on every machine, and it contains a list of users who must log onto the local domain to access that machine. The global user group Domain Users is automatically added to the users in the Users object.
The following script binds to the Users object on a machine and lists the users contained in the object:
Dim myUsers Dim member Set myUsers = GetObject("WinNT://mymachine/users") For Each member In myUsers WScript.Echo member.Class & ": " & member.Name Next
Notice the use of the Class property of each user returned from the Users object. The users list returned may also contain groups, so the Class property is useful for differentiating which names returned belong to users and which belong to groups, since the Filter property does not exist for the Users object.