Other Languages - vbscript using array - Asked By Jay Seems on 15-Sep-11 06:31 PM

Using Prompt for input, I am able to add an account to multiple systems.

Problem: When calling Sub Preuser to check for existing user name on the systems, only the first system in array is being used. The Sub AddUser appears to be working correctly.

Any Ideas on what is wrong?


' ------- TEXT USED ----------

Title = "New User Tools v1.1"

strGroup = "Users"

' ------ END TEXT USED --------



'------ GET INPUTS FROM USER ----------

Dim strUserName, strFullName, strPassword

If Msgbox("Would you Like to Add a User?" , vbYesNo, Title) = vbYes then

Call GetInputs

Sub GetInputs

Do

strUserName = InputBox("Please Enter User Name.",Title)

If strUserName = ""Then

If MsgBox("Are you Sure you want to Quit?" , vbYesNo, Title)= VbNo Then

End If

End if

Loop Until strUserName <> ""

Do

strFullName = InputBox("Please Enter Your Full Name.", Title)

If strFullName = "" Then

If MsgBox("Are you Sure you want to Quit?" , vbYesNo, Title)= VbNo Then 





























End If

End If

Loop Until strFullName <> ""

Do

strPassword = InputBox("Please Enter Password.",Title)

If strPassword="" Then

If MsgBox("Are you Sure you want to Quit?" , vbYesNo, Title)= VbNo Then

End If

End If

Loop Until strPassword<>""

Call PreUser()

Call AddUser()

End Sub















' ------ END INPUTS ---------------











'SCRIPT MODIFIED AT THIS POINT BY

' ----- CODE TO PRECHECK FOR USER ACCT ----------

Sub PreUser

arrComputers2 = Array("PC-1", "PC-2")




For Each strComputer In arrComputers2


Set objComputer = GetObject("WinNT://" & strComputer, "")

 


objComputer.Filter = Array("user", strUserName)

For Each User In objComputer

If lcase(User.Name) = lcase(strUserName) Then









'objUser.SetPassword "Swer45R$"

'objUser.Put "PasswordExpired", 1

'objUser.SetInfo

WScript.Echo User.Name & " already exists and password reset."

'WScript.Quit



End If

Next

Next





 

'Wscript.Echo "This user account does not exist."

End Sub

  

' ----- END CODEODE TO PRECHECK FOR USER ACCT ----------


Sub AddUser



Dim objNetwork, strComputerName, objComputer

arrComputers = Array("PC-1", "PC-2")





For Each strComputer In arrComputers

Set objComputer = GetObject("WinNT://" & strComputer, "")

  

Set objUser = objComputer.Create("user", strUserName)

  

objUser.SetPassword strPassword

objUser.FullName = strFullName

objUser.Put "Description", strUserName

objUser.Put "PasswordExpired", 1

objUser.SetInfo

  

' ----- CODE TO ADD USER TO GROUP -------











Set objGroup = GetObject("WinNT://" & strComputer & "/" & strGroup)

objGroup.Add("WinNT://" & strComputer & "/" & strUserName)

' ----- END CODE TO ADD USER TO GROUP -----




Next

 

Call MsgBox ("User Name: " & strUserName & vbCrLf & "Password: " &strPassword & VbCrLf & VbCrLf & "Please Write This Information Down.", 64, Title)

'Call AddGroup



End Sub

' ----- END CODE TO ADD USER -------



'------ EXIT -----


Sub CleanUp

Call MsgBox ("Click OK To Exit the Program",0, Title)

WScript.quit

End Sub

End If

'----- EXIT ------









Manish Mishra replied to Jay Seems on 29-Nov-11 04:56 AM
Hi,
Your code for preuser is fine. I hope the problem is with the objComputer.Filter. you should remove this line and then check your code. Hope it should work fine.
As of now its filtering out the single name and the loop stops there only.