Creating and Manipulating Shares with ADSI
This Web exclusive sidebar shows you how to write scripts that create and list shares on a Windows 2000 (Win2K) or Windows NT server.
June 30, 1999
You can use Active Directory Service Interfaces (ADSI) to help you create and manipulate shares. Listing 1 shows how easily you can create shares with ADSI. After you declare your adsComputer and adsFileShare variables, you bind to the LanmanServer object on the computer on which you want to create the shares. LanmanServer is the object name of the server service that runs on all Windows NT and Windows 2000 (Win2K) computers. You bind to this object because NT's predecessor was LAN Manager. This former OS introduced the shares you're likely to be familiar with.
Next, you use the IADsContainer::Create method to create an object of class FileShare and apply the IADsFileShare property methods to set the path, description, and maximum number of users. On an NT or Win2K server, you can grant all users access to a share or limit access to as many users as you want. On an NT or Win2K workstation, you can grant all users access to a share or limit access to between 1 and 10 users at a time. The latter restriction is due to the 10-connection limit that the OS imposes. The values that the IADsFileShare::MaxUserCount method accepts are –1 (which grants all users access), any numerical value between 1 and 10 on workstations, and within reason, any numerical value on the server family of OSs.
Finally, you end the script with IADs::SetInfo. SetInfo writes the information from the cache to the directory.
Enumerating existing shares is just as easy as creating them. Listing 2 contains a script to enumerate shares. (However, the script doesn't list hidden shares.) This code is similar to that in Listing 1. Screen 1 contains the output from Listing 2.
About the Author
You May Also Like