您的位置:首页 > 编程语言 > VB

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

2007-02-12 11:40 671 查看
http://support.microsoft.com/kb/169398/zh-cn MSDN支持
如何操纵文件共享使用 ADSI (VB 示例)

概要

loadTOCNode(1, 'summary');
使用 Active Directory Service Interfaces (ADSI) 来操纵如上 VisualBasic 示例代码, 文件共享。


更多信息

loadTOCNode(1, 'moreinformation');
您必须从 www.microsoft.com/ntserver/info/adsi.htm, 安装运行 ADSI 库 (ADS.EXE) 可用, 然后添加对 ActiveDirectory DS 类型库引用。

注意: Windows 2000 包括 ADSI 2.5 运行时间。 安装上述运行时则不需要。

以下代码首先在服务器上获取文件共享对象并读取其路径属性。 然后在服务器上获取 fileservice 对象, 使用它来枚举服务器上共享、 创建新共享 //SERVER/newshare 对于 C:/, 并删除共享它刚刚创建。 可以忽略 DOMAIN/ 在代码中, 但可能看到一些性能下降由其他浏览以查找 SERVER:
[code]   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

[/code]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: