初识 MICROsoft ADSI

ADSI的具体介绍:


活动目录服务接口(ADSI)是一类开放接口,这类接口从不同的网络提取目录服务的功能为网络资源的访问及管理提供一个单一的视图。不管是哪个网络环境包含这些资源,系统管理员和开发人员都可以利用ADSI的功能来列举和管理一个目录服务里的资源。这个目录可以是基于LDAP的目录,也可以是基于NDS或基于NTDS的目录。至于是哪种并没有关系,只要服务提供者所提供的目录服务是有效的。

MSDN参考:

http://msdn.microsoft.com/en-us/library/aa772218%28VS.85%29.aspx

Com对象的引用:Active DS Type Library

 

例子:

用vbs从本地 Administrators 组中删除组

 

strComputer = "atl-fs-01" 
Set objAdmins = GetObject("WinNT://" & strComputer & "/Administrators") 
Set objGroup = GetObject("WinNT://fabrikam/finance") 
objAdmins.Remove(objGroup.ADsPath)

1. 如何偵測NT使用者所在的群組 ?

dsRoot = "WinNT://domain/userid"
set wshShell = Wscript.CreateObject("Wscript.Shell")
set dsObj = GetObject(dsRoot)
For Each Prop In dsobj.groups
    wshshell.popup Prop.Name
Next 'Prop

 

2. 如何透過 ADSI 更新 NT 的使用者設定 ?

set user = GetObject("WinNT://domain/user")
     User.FullName = FirstNameVar
     User.HomeDirectory = UserHome
     User.Profile = "\Server\Share\user"
     User.LoginScript = LogonScript
     User.Description = "Description"

     User.setinfo
 

3. 如何列出NT網路中的所有網域 DOMAIN?

Using ADSI you can do the following...
Dim adsNS, adsDomain
Set WSHShell = WScript.CreateObject("WScript.Shell")
Set adsNS = GetObject("WinNT:")
adsNS.Filter = Array("domain")
For Each adsDomain In adsNS
WSHShell.popup adsDomain.ADsPath
Next 'adsDomain
 

4. 如何建立 NT 使用者?

On Error Resume Next
strUser="UserID"
Set oDomain = GetObject("WinNT://YourDomain")
Set oUser = oDomain.Create ("user", strUser)
If (err.number = 0) Then 'If not 0 then user ID already exists
    oUser.SetInfo
oUser.SetPassword "mypassword"
oUser.SetInfo
End If
 

5. 如何建立NT的使用者群組 ?

StrGroup="NewGroupName"
Set oDomain = GetObject("WinNT://YourDomain")
Set oGroup = oDomain.Create ("group", strGroup)
OGroup.SetInfo

您只要將上述程式碼,放置在 NT 的任何目錄中,將副檔名存為 .vbs並直接執行,就可以看到ADSI的威力囉!

Ok , 有關

ADSI 的相關資訊,您可以在下列位址中找到更多資訊 :

ADSI User Group
http://www.15seconds.com/focus/ADSI.htm
Understanding ADSI
http://www.15seconds.com/Issue/980304.htm
Configuring NTLM with ADSI
http://www.15seconds.com/Issue/980318.htm
posted @ 2009-11-05 19:38  db's jim  阅读(339)  评论(0编辑  收藏  举报