CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  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.

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: How to get user data from VB Script?

    swap811, please use &#091;CODE] tags when posting code.

  3. #3
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: How to get user data from VB Script?

    Download ScriptoMatic for Active Directory. It will write scripts in a few languages, based on combo boxes. ScriptoMatic 2.0 is for non AD networks
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

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