如何操纵文件共享使用 ADSI (VB 示例)

    技术2022-05-11  52

    http://support.microsoft.com/kb/169398/zh-cn  MSDN支持

    如何操纵文件共享使用 ADSI (VB 示例)

     

    概要

    <script type="text/javascript">loadTOCNode(1, 'summary');</script> 使用 Active Directory Service Interfaces (ADSI) 来操纵如上 VisualBasic 示例代码, 文件共享。

     

    更多信息

    <script type="text/javascript">loadTOCNode(1, 'moreinformation');</script> 您必须从 www.microsoft.com/ntserver/info/adsi.htm, 安装运行 ADSI 库 (ADS.EXE) 可用, 然后添加对 ActiveDirectory DS 类型库引用。 注意: Windows 2000 包括 ADSI 2.5 运行时间。 安装上述运行时则不需要。 以下代码首先在服务器上获取文件共享对象并读取其路径属性。 然后在服务器上获取 fileservice 对象, 使用它来枚举服务器上共享、 创建新共享 //SERVER/newshare 对于 C:/, 并删除共享它刚刚创建。 可以忽略 DOMAIN/ 在代码中, 但可能看到一些性能下降由其他浏览以查找 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  

    最新回复(0)