Creating and Manipulating Shares with ADSI
The following code shows how easily you can create shares with ADSI:
Dim objComputer, objFileShare Set objComputer = GetObject("WinNT://mydomainorworkgroup/mycomputer/LanmanServer") Set objFileShare = objComputer.Create("FileShare", "MyNewShare") objFileShare.Path = "c:\mydirectory" objFileShare.Description = "My new Share" objFileShare.MaxUserCount = 8 objFileShare.SetInfo
After we declare the objComputer
and
objFileShare
variables, we bind to the
LanmanServer
object on the computer on which we
want to create the shares. LanmanServer
is the
object name of the server service that runs on all Windows NT and
later computers. We bind to this object because NT’s
predecessor was LAN Manager and is still present to a large extent in
the Windows OS.
Next, we 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, Windows 2000, or
Windows Server 2003 server, you can grant all users access to a share
or limit access to as many users as you want. On a 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 ...
Get Active Directory, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.