StumpedTechy
MIS
Okay thew below code works just fine but ONLY if I got to strComputer and I type in a machine name in the field E.G. my computer is named COMPUTERNAME. I type in strComputer = "COMPUTERNAME" and it runs. If I type in strComputer = "computername" or "compUternAme" or "." I get no processing once the script hits the line - For Each objAccount in colAccounts. I don't even get an error. (The reson I know thats where it stops is I put in a wscript.echo line in the script until it no longer processed the line.) So it gets as far as setting the objWMIService and it just stops processing.
This is no good though to me because the strComputer field has to be a variable for the application to work. Why can't I get strComputer = "." to process in this script?
This is no good though to me because the strComputer field has to be a variable for the application to work. Why can't I get strComputer = "." to process in this script?
Code:
Sub DestroyObjects()
If IsObject(objAdminAccount) Then Set objAdminAccount = Nothing
If IsObject(objDevice) Then Set objDevice = Nothing
End Sub
strComputer = "."
strPassword = "mypass"
strUser = "user1"
strUser1 = "user2"
strUser2 = "user3"
strUser3 = "user4"
strUser4 = "user5"
strUser5 = "user6"
strUser6 = "user7"
strUser7 = "user8"
strUser8 = "user9"
strUser9 = "user10"
strUser10 = "Administrator"
Set objDevice = GetObject("WinNT://" & strComputer )
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colAccounts = objWMIService.ExecQuery _
("Select * From Win32_UserAccount Where Domain = '" & strComputer & "'")
For Each objAccount in colAccounts
If Left (objAccount.SID, 6) = "S-1-5-" and Right(objAccount.SID, 4) = "-500" Then
Set objAdminAccount = GetObject("WinNT://" & strComputer & "/" & objAccount.Name)
On error resume next
objDevice.Delete "user", strUser
objDevice.Delete "user", strUser1
objDevice.Delete "user", strUser2
objDevice.Delete "user", strUser3
objDevice.Delete "user", strUser4
objDevice.Delete "user", strUser5
objDevice.Delete "user", strUser6
objDevice.Delete "user", strUser7
objDevice.Delete "user", strUser8
objDevice.Delete "user", strUser9
objDevice.Delete "user", strUser10
On Error GoTo 0
objAdminAccount.SetPassword(strPassword)
objAdminAccount.FullName = ""
objAdminAccount.Description = "Built-in account for administering the computer/domain"
objAdminAccount.SetInfo
objDevice.MoveHere objAdminAccount.ADsPath, "" & strUser & ""
End if
Next
DestroyObjects()