VBScript for NT4.0

VBScript for NT4.0

Post by Script Grasshopp » Fri, 25 Jul 2003 04:44:19


I'm trying to connect to an Active Directory Service running on a
Windows 2000 domain using a visual basic script.  I'm executing the
script on a Windows NT 4.0 Workstation with vbscript v5.1 I can't seem
to open the connection without getting the error..  "Provider Can't be
found"  What is the valid provider for ADSI?  I've tried "WinNT://",
"LDAP://" and "ADsDSOObject"  I ultimately want to obtain the list of
groups that a domain user belongs to.  Any help would be very much

Option Explicit
Dim aCon, aCmd, aRst, sResultText
Set aCon = CreateObject("ADODB.Connection")
Set aCmd = CreateObject("ADODB.Command")
aCon.Provider = "ADsDSOObject"
aCon.Open ' Error received on this line
aCmd.ActiveConnection = aCon    
aCmd.CommandText = "<LDAP://OU=IT Admins,OU=PSC,OU=Practice
Office,dc=us,dc=deloitte,dc=com>;" _
        & "(objectClass=user);name,SamAccountName,givenName," _
        & "sN,telephonenumber;subTree"
Set aRst = aCmd.Execute()
Do While Not aRst.EOF
        sResultText = sResultText _
                & aRst.Fields("samaccountname") _
                & ", " & aRst.Fields("givenname") _
                & ", "    & aRst.Fields("sN") _
                & ", " & aRst.Fields("telephonenumber") _
                & vbCRLF


VBScript for NT4.0

Post by david moo » Mon, 28 Jul 2003 12:40:07

Try the following script.  This returns the list of users that belong
to a particular group and saves them to a text file.  It could be
easily modified to return the groups that a user belongs to.


Sub listMembers (GroupName, Domain, OutFile)
'Purpose: Lists members of a Windows group
' GroupName - The name of the Windows Group as a String
' Domain - The name of the Domain as a String
' OutFile - The file path for the output file as String
  dim grp
  dim usr
  dim strGroupName
  dim strGroupDomain
  dim fso
  dim txt

  set fso = CreateObject("Scripting.FileSystemObject")
  set txt = fso.CreateTextFile(OutpFile, True)

  set grp = GetObject("WinNT://" & Domain & "/" & GroupName &

  txt.WriteLine "Users in " & Domain & "/" & GroupName

  For Each usr in grp.Members
    txt.WriteLine usr.Name

  set fso = Nothing
End Sub

Call listMembers("Name of Group Here", "Domain Name Here",


VBScript for NT4.0

Post by Steve RONDE » Mon, 28 Jul 2003 12:50:10

I just tried your script. I had the same issue than your, but it got
corrected when I added the following lines to the script:

>aCon.Provider = "ADsDSOObject"

aCon.Properties("User ID") = "cn=username,dc=corp,dc=company,dc=com"
aCon.Properties("Password") = "password_here"
aCon.Properties("Encrypt Password") = True

Quote:>aCon.Open ' < no more error

Those lines are set to use a user account / password to access the
Active Directory. This user account could be an admin account from
your Windows 2000 domain, but since you apparently only need to get
(and not set) informations, you can use any existing account. In
Windows 2000, you cannot anonymousely connect to the Active Directory
by default for security reasons. Then, since you get connected through
the LDAP port, you need to specify a user account.
I guess you'll get another error on the line:
Quote:>aCmd.CommandText = "<LDAP://OU=IT Admins,O.......

You'll neet to specify a server since you are running the script from
aCmd.CommandText = "<LDAP://DCNAME/OU=IT Admins,O...
Where DCNAME is the name of a Domain Controller of your Windows 2000
Forest. It can also be mentionned as dcname.corp.company.com

I Hope it helped