Microsoft® Windows® 2000 Scripting Guide
« Previous | Next »
Folders are published in Active Directory to make it easier to identify all the shares on your network. After a folder is shared and published, you can locate it using tools such as Active Directory Users and Computers.
In addition, ADSI can be used to retrieve a list of all the folders that have been published in Active Directory. This can be done by constructing a script that returns all instances of the Volume class.
Scripting Steps
Listing 11.39 contains a script that enumerates the shared folders published in Active Directory. To carry out this task, the script must perform the following steps:
- Include the On Error Resume Next statement. Without this statement, the script fails if it is unable to find any published folders in Active Directory.
- Create a constant named ADS_SCOPE_SUBTREE and set the value to 2. This is used to specify a search that begins in the Active Directory root and proceeds to search all the child containers as well.
- Create an instance of the Active Directory connection object (ADODB.Connection).
- Create an instance of the Active Directory command object (ADODB.Command).
The command object allows you to issue queries and other database commands using the Active Directory connection.
- Set the provider property of the connection object to the Active Directory provider (ADsDSOObject). This is the OLE database provider for ADSI.
- Set the active connection to the Active Directory connection.
- Set the command text for the Active Directory command object to the SQL query that retrieves all the published shared folders from fabrikam.com.
- Specify values for time-out, search scope, and caching.
- Execute the SQL query.
- When the set of published shared folders is returned, use the MoveFirst method to move to the first share in the recordset.
- For each share in the recordset, echo the share name, the UNC name, and the name of the user responsible for managing the share.
Listing 11.39 Enumerating Published Shared Folders
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| On Error Resume Next Const ADS_SCOPE_SUBTREE = 2 Set objConnection = CreateObject( "ADODB.Connection ") Set objCommand = CreateObject( "ADODB.Command ") objConnection.Provider = "ADsDSOObject " objConnection.Open "Active Directory Provider " Set objCOmmand.ActiveConnection = objConnection objCommand.CommandText = "SELECT Name, unCName, ManagedBy FROM " _ & "'LDAP://DC=Fabrikam,DC=com' WHERE objectClass='volume' " objCommand.Properties( "Timeout ") = 30 objCommand.Properties( "Searchscope ") = ADS_SCOPE_SUBTREE objCommand.Properties( "Cache Results ") = False Set objRecordSet = objCommand.Execute objRecordSet.MoveFirst Do Until objRecordSet.EOF Wscript.Echo "Share Name: " & objRecordSet.Fields( "Name ").Value Wscript.Echo "UNC Name: " & objRecordSet.Fields( "uNCName ").Value Wscript.Echo "Managed By: " & objRecordSet.Fields( "ManagedBy ").Value objRecordSet.MoveNext Loop |
Send us your feedback | « Previous | Next » |