CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Threaded View

  1. #1
    Join Date
    Jul 2009
    Posts
    6

    How to get user data from VB Script?

    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

    Code:
    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.
    Last edited by HanneSThEGreaT; July 23rd, 2010 at 01:19 AM. Reason: Added [CODE] tags.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured