Question : VBS Script to not create user, if user is existing in active directory

Hi everyone.

I need some help here.

I have made a vbs script, that will create user in active directory, but the problem is, everytime i run this script, the user password get reset back to the old password, is there anyone that can help me whit a way, so it will not happe ???

Answer : VBS Script to not create user, if user is existing in active directory

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
SCRIPT: 
'**************************************************************************************
'Created:    04/08/2002 
'Author:     Yi Helen Wang
'Purpose:    Searching users through an Active Directory (AD) of
'            Windows 2000 to insure against duplicating when 
'            a new user is added into AD
'Keywords:   ADO and ADSI 2.5 or up
'Reviewed:   05/13/2002
'Comment:    You have to assign a permission to get Active Directory 
'      information.  This program is run locally or remotely
'***************************************************************************************
on error resume next

dim oContainer,searchpath
dim oRoot
dim oConnect, oCommand, rs
dim strConnect, strDomainCtrl, strOU
dim cntuser, newuser, strCN, strSearchUser

newuser = false
cntuser = 0

'to get LDAP namespace
set oRoot = GetObject("LDAP: //RootDSE")
call ShowError("Permission issues !")
strDomainCtrl = oRoot.Get("defaultNamingContext")

strOU = InputBox("Please entry an Organization Unit Name to search: ", "Searching","Legal")
if Len(Trim(strOU)) = 0 then
  msgbox "No information typed in!" 
else
  strConnect = "LDAP://OU=" & strOU & ", " & strDomainCtrl
  set oContainer = GetObject(strConnect)
  call ShowError("OUNameNotExist")
  
  searchpath = oContainer.ADsPath

  strSearchUser = InputBox("Please entry the user searched initial: ", "Searching", "sls")
  if Len(Trim(strSearchUser))=0  then
    msgbox "No information typed in!"
  else
    'Using ADO to query the Active Directory for a particule user
    set oConnect = CreateObject("ADODB.Connection")
    set oCommand = CreateObject("ADODB.Command")
    call ShowError("ADOProblems")

    'opening the connection
    oConnect.Provider = "ADsDSOObject"    
    oConnect.Open "Active Directory Provider"
    call ShowError("ADOProvider")
     'creating a command object for this connection
     Set  oCommand.ActiveConnection = oConnect

     strCN = strSearchUser
     DO WHILE newuser <> True
  
      oCommand.CommandText = "SELECT samAccountName FROM '" & searchpath & "' WHERE objectClass='user' AND samAccountName = '" & strSearchUser & "'"

      'creating a recordset based on the ADO command
      set rs = oCommand.Execute
 
      'Navigating the record set
      if rs.EOF and rs.BOF then
        msgbox  "New user"
        newuser = True
      else
       cntuser = cntuser + 1
       'rename and check again till no duplication
       strSearchUser = left(strCN,1) & right(strCN,1) & cntuser
       msgbox  "Rename CN as " & strSearchUser
       set rs = nothing
     end if

    LOOP
  end if
end if
    
sub ShowError(strErr)
  if err <> 0 then

   if err = 432 or err=70 then
    wscript.echo "Permission issues to run the program"
    wscript.quit   
   else
    select case strErr
     case "OUNameNotExist"
      wscript.echo "OU name is not correct or not exist !"
      wscript.quit
     case "ADOProblems"
      wscript.echo "ADO problems!"
      wscript.quit
     case "ADOProvider"
      wscript.echo "ADO Provider Problems!"
      wscript.quit
    end select
   end if

  end if
end sub
Random Solutions  
 
programming4us programming4us