求助:有关adsi访问活动目录的问题(我是写java的,vb不会啊)

zyx_154 2005-08-09 11:11:02
小弟是写java的,但是最近工作需要,要修改一端vb的代码,时间紧迫,实在是没太多时间学习vb,只好前来求助

代码如下:
Dim con As New Connection
Dim rs As New Recordset
Dim Com As New Command

'Open a Connection object
con.Provider = "ADsDSOObject"
con.Open "Active Directory Provider"

'Create a command object on this connection
Set Com.ActiveConnection = con
Com.CommandText = "select name from 'LDAP://DC=ADTEST,DC=COM' where objectClass='*' ORDER BY NAME"

'Set the preferences for Search
Com.Properties("Page Size") = 1000
Com.Properties("Timeout") = 30 'seconds
Com.Properties("searchscope") = ADS_SCOPE_SUBTREE

'Execute the query
Set rs = Com.Execute

' Navigate the record set
While Not rs.EOF
Debug.Print rs.Fields(Name).Value
rs.MoveNext
Wend

运行时报编译错误:用户定义类型未定义

那位能指点一下,万分感谢!!
...全文
88 点赞 收藏 5
写回复
5 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
crycoming 2005-08-09
加载ADS_SCOPE_SUBTREE 的定义模块 就是包含 Const ADS_SCOPE_SUBTREE= 的模块
回复
crycoming 2005-08-09
工程-->引用-->Microsoft ActiveX Data Objects 2.6 Library
回复
zyx_154 2005-08-09
crycoming(瞎编):
我现在的环境是 域ADTEST.COM , 测试的机器加入了该域,ping装有AD的机器也没有问题
可把你的代码里面的'LDAP://DC=fabrikam,DC=com'的值改成'LDAP://DC=ADTEST,DC=COM'后,运行时还是报"Table does not exist"
回复
crycoming 2005-08-09
'---------------------------------------------------------------
' Returns the name and location for all the computer accounts in
' Active Directory.
'---------------------------------------------------------------
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.CommandText = _
"Select Name, Location from 'LDAP://DC=fabrikam,DC=com' " _
& "where objectClass='computer'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 30
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
Wscript.Echo "Computer Name: " & objRecordSet.Fields("Name").Value
Wscript.Echo "Location: " & objRecordSet.Fields("Location").Value
objRecordSet.MoveNext
Loop

回复
zyx_154 2005-08-09
谢谢,现在可以编译了
但是在运行是还有问题,执行Com.Execute的时候报 -2147217865(80040e37) table does not exist
这是什么原因? 是我的活动目录配置问题还是查询语句的问题?
回复
相关推荐
发帖
VB基础类
创建于2007-09-28

7518

社区成员

VB 基础类
申请成为版主
帖子事件
创建了帖子
2005-08-09 11:11
社区公告
暂无公告