Enumerating Published Folders

Microsoft® Windows® 2000 Scripting Guide

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:

  1. 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.
  2. 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.
  3. Create an instance of the Active Directory connection object (ADODB.Connection).
  4. 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.

  5. Set the provider property of the connection object to the Active Directory provider (ADsDSOObject). This is the OLE database provider for ADSI.
  6. Set the active connection to the Active Directory connection.
  7. Set the command text for the Active Directory command object to the SQL query that retrieves all the published shared folders from fabrikam.com.
  8. Specify values for time-out, search scope, and caching.
  9. Execute the SQL query.
  10. When the set of published shared folders is returned, use the MoveFirst method to move to the first share in the recordset.
  11. 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 Send us your feedback « Previous | Next »   


Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 635

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net