Microsoft KB Archive/169398

= How To Manipulate File Shares with ADSI (VB Sample) =

Article ID: 169398

Article Last Modified on 3/29/2007

-

APPLIES TO

 Microsoft Visual Basic 6.0 Learning Edition, when used with:  Microsoft Windows 2000 Standard Edition

 Microsoft Windows NT 4.0

 Microsoft Windows 98 Standard Edition

 Microsoft Windows 95</li></ul> </li> Microsoft Visual Basic 4.0 Professional Edition, when used with:  Microsoft Windows 2000 Standard Edition</li></ul>

 Microsoft Windows NT 4.0</li></ul>

 Microsoft Windows 98 Standard Edition</li></ul>

 Microsoft Windows 95</li></ul> </li> Microsoft Visual Basic 6.0 Professional Edition, when used with:  Microsoft Windows 2000 Standard Edition</li></ul>

 Microsoft Windows NT 4.0</li></ul>

 Microsoft Windows 98 Standard Edition</li></ul>

<ul> <li>Microsoft Windows 95</li></ul> </li> <li>Microsoft Visual Basic 4.0 Enterprise Edition, when used with: <ul> <li>Microsoft Windows 2000 Standard Edition</li></ul>

<ul> <li>Microsoft Windows NT 4.0</li></ul>

<ul> <li>Microsoft Windows 98 Standard Edition</li></ul>

<ul> <li>Microsoft Windows 95</li></ul> </li> <li>Microsoft Visual Basic 6.0 Enterprise Edition, when used with: <ul> <li>Microsoft Windows 2000 Standard Edition</li></ul>

<ul> <li>Microsoft Windows NT 4.0</li></ul>

<ul> <li>Microsoft Windows 98 Standard Edition</li></ul>

<ul> <li>Microsoft Windows 95</li></ul> </li> <li>Microsoft Visual Basic 4.0 Standard Edition, when used with: <ul> <li>Microsoft Windows 2000 Standard Edition</li></ul>

<ul> <li>Microsoft Windows NT 4.0</li></ul>

<ul> <li>Microsoft Windows 98 Standard Edition</li></ul>

<ul> <li>Microsoft Windows 95</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q169398

<div class="summary_section">

SUMMARY
You can use Active Directory Service Interfaces (ADSI) to manipulate file shares as shown in the Visual Basic sample code below.

<div class="moreinformation_section">

MORE INFORMATION
You must install the ADSI runtime (ADS.EXE) available from www.microsoft.com/ntserver/info/adsi.htm, and then add a reference to Active DS Type Library.

Note: Windows 2000 includes the ADSI 2.5 run time. Installation of the above runtime is not required.

The following code first gets a fileshare object on a server and reads its path property. Then it gets a fileservice object on a server, uses it to enumerate the shares on the server, creates a new share \\SERVER\newshare for C:\, and deletes the share it just created. You can omit the DOMAIN\ in the code below, but you may see some performance degradation caused by additional browsing to find the SERVER:

Sub foo

Dim comp As IADsComputer Dim serv As IADsService Dim fserv As IADsContainer Dim share As IADsFileShare Dim shareNew As IADsFileShare Dim v As Variant

' Replace DOMAIN, SERVER & SHARE with the appropriate ' domain, server and share names Set share = GetObject("WinNT://DOMAIN/SERVER/lanmanserver/SHARE") v = share.Path ' Gets directory path on server Set share = nothing

' Replace DOMAIN & SERVER with the appropriate domain and server names Set fserv = GetObject("WinNT://DOMAIN/SERVER/lanmanserver")

' Enumerate existing shares For Each share In fserv v = share.Class v = share.ADsPath v = share.HostComputer v = share.Path Next share

' Create share in fileservice container Set shareNew = fserv.Create("fileshare", "newshare") shareNew.Path = "C:\" shareNew.SetInfo ' Commit new share

' Delete share fserv.Delete "fileshare", "newshare"

' Fails since share is gone shareNew.GetInfo

End Sub

<div class="references_section">