如何在VB脚本中从AD获取用户数据? [英] How to get the user data from AD in VB Script?

查看:297
本文介绍了如何在VB脚本中从AD获取用户数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有2个广告.运行脚本时,我将向其中一个AD提供用户ID,并获取所需的用户数据.然后使用所有这些数据,我将在其他AD中创建新用户.

如果我从同一AD本身运行脚本,则可以正常工作,但是当我从其他域中的另一台计算机运行脚本时,则出现问题.错误提示为访问被拒绝".

为了检查访问权限,我在AD上共享了一个文件夹,并尝试从命令提示符下访问它.该文件夹可以访问.

以下是我的脚本出现问题的一部分

Hi,
I am having 2 AD. While running my script I will be providing userid to one of the AD and getting the required user data. Then using all that data, I will be creating new user in other AD.

If I run my script from same AD itself then it is working fine but when I am running it from some another machine in different domain then it is problem. It''s giving error as "access denied".

To check the access I shared one folder on AD and tried accessing it from command prompt. That folder was accessible.

Below is part of my script which is giving problem

strNTName = "abcd"
strDNSDomain = "DC=AD,DC=COM"
' Use ADO to search Active Directory.
Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Properties("User ID") = "abcd"
adoConnection.Properties("Password") = "abcd_wxyz"
'adoConnection.Properties("Encrypt Password") = TRUE
'adoConnection.Properties("ADSI Flag") = 3

'adoConnection.Open
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnection = adoConnection
' Search entire domain.
strBase = "<LDAP://" & strDNSDomain & ">"
' Search for all users.
strFilter = "(&(objectCategory=person)(objectClass=user)(samAccountName=" & strNTName & "))"
' Comma delimited list of attribute values to retrieve.
'strAttributes = "givenName,sn,mail,userPrincipalName"
strAttributes = "givenName,sn"
' Construct the LDAP query.
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
' Run the query.
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False
Set adoRecordset = adoCommand.Execute
MsgBox adoRecordset.RecordCount



任何人都可以帮助解决这个问题吗?
在此先感谢您.



Can anyone please help to solve this problem?
Thanks in advance.

推荐答案

在大多数情况下,LDAP连接都不正常.您总是可以尝试使用公共LDAP服务器来测试代码.

http://www.emailman.com/ldap/public.html [ http://www.keutel.de/directory/public_ldap_servers.html [
Most of the time the LDAP connection isn''t okay. You could always try a public LDAP server for testing the code.

http://www.emailman.com/ldap/public.html[^]

http://www.keutel.de/directory/public_ldap_servers.html[^]

Good luck!


这篇关于如何在VB脚本中从AD获取用户数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆