I might just be being stupid, but I can't see a check for password on any of the scripts so far - ie I say I'm user jbloggs and it just accepts that!
The script below takes user, password and group on the command line (eg checkpassword.vbs /user:jbloggs /password:ReallyReallySecret /group:year13) and does stuff if username and password are correct and user is in the group. I've tried to add helpful comments but shout if it's not clear!
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_1779 = 1
Const ADS_NAME_TYPE_NT4 = 3
'get the DNS name of the domain - eg dc=ic,dc=ac,dc=uk
'now find the NETBIOS name of the domain so we can do \user later on
Set oTrans = CreateObject("NameTranslate")
oTrans.Init ADS_NAME_INITTYPE_GC, ""
oTrans.Set ADS_NAME_TYPE_1779, sDNS
sDomain = oTrans.Get(ADS_NAME_TYPE_NT4)
'find the distinguished name of this user
'function will query LDAP anonymously - quits if the user is not there
if sDN1="N/A" then
wscript.echo "Can't find user"
'now we know the user exists; is the password they gave us valid?
'carry out the same query but this time connect to the domain using the password
if sDN1<>sDN2 then 'password is not valid
wscript.echo "Wrong password"
'username and password are valid; is the user in the group
'bind to user object
set oUser=getobject("LDAP://" & sDN2)
'assume user is not in group
for each oGroup in oUser.groups
'check for each group - make lcase just to avoid problems with case
if lcase(oGroup.samaccountname)=lcase(sGroup) then
'process appropriately for in/out of group
if bInGroup then
wscript.echo "In group, mapping drives"
wscript.echo "Not in group " & sGroup
'kludgy but saves unwanted errors
on error resume next
'set up connection to Active Direcotry
sAttributes = "distinguishedName"
Set oConn = CreateObject("ADODB.Connection")
oConn.Provider = "ADsDSOObject"
'are we doing anon bind?
if not bAnon then
oConn.Properties("User ID") = sDomain & sUser
oConn.Properties("Password") = sPassword
oCommand.ActiveConnection = oConn
sFilter = "(samaccountname=" & sNTName & ")"
'query built here has domain name; filter based on username; only attribute needed is distinguished name and subtree means search whole directory
sQuery = sBase & ";" & sFilter & ";" & sAttributes & ";subtree"
oCommand.CommandText = sQuery
Set oRS = oCommand.Execute
'will be EOF if not found
if ors.eof then
'return either N/A for not found or error (eg bad password) and distinguished name otherwise
on error goto 0