‘Written by Jase McCarty
‘Date: 03/29/2006
‘
‘UPD8SVCS.vbs
‘
‘Description: Change the password on a local
‘or remote system for a Service that has
‘”Logon As” set for a Domain Account
‘Useful for Servers when a service account
‘has a password change
‘***********************************************************
Dim strUserDomain,strUserName,strPassword,strComputer
Dim CSComputerName,CSAccount,CSPassword,objWMIService
Dim objService
If Wscript.Arguments.Count < 2 Then
Wscript.Echo “Usage: UPD8SVCS.vbs USERNAME PASSWORD COMPUTERNAME”
Wscript.Quit
Else
‘Create a Shell Object & be able to get environment variables
Set shellobj = CreateObject(“Wscript.Shell”)
Set env = shellobj.Environment(“process”)
‘(could be modified to be an attribute)
strUserDomain = env(“USERDOMAIN”)
strUserName = Wscript.Arguments(0)
strPassword = Wscript.Arguments(1)
‘Check to make sure we have enough arguements (2 or more)
If Wscript.Arguments.Count > 2 Then
‘If we 3, then the Computername will be the 3rd arguement
strComputer = Wscript.Arguments(2)
Else
‘If we only receive the first 2, then the Computername
‘will be the local computer
strcomputer = env(“COMPUTERNAME”)
End If
‘Call the ChangeServices subroutine
Call ChangeServices(strComputer,strUserDomain & “” & strUserName,strPassword)
WScript.Quit
End If
‘The ChangeServices SubRoutine
‘This requires a computername, account,and password to be passed to it
Sub ChangeServices(CSComputerName,CSAccount,CSPassword)
Set objWMIService = GetObject(“winmgmts:\” & CSComputerName & “rootcimv2”)
Set colItems = objWMIService.ExecQuery(“Select * from Win32_Service”,,48)
‘Loop through the array
For Each objService in colItems
‘change the password to the one specified
If Lcase(objService.StartName) = LCase(CSAccount) Then
‘Make the credentials change
errReturn = objService.Change(,,,,,,CSAccount,CSPassword)
‘Write to the screen and the computer’s event log, the success or failure
If err.number <> 0 then
shellobj.LogEvent 1,”Failure Changing Username and Password for ” _
& objService.DisplayName & ” run by user ” & CSAccount & “.”
Wscript.Echo “Failure Changing Username and Password for ” _
& objService.DisplayName & ” run by user ” & CSAccount & “.”
Else
shellobj.LogEvent 0,”Successfully Changed Username and Password for ” _
& objService.DisplayName & ” run by user ” & CSAccount & “.”
Wscript.Echo “Successfully Changed Username and Password for ” _
& objService.DisplayName & ” run by user ” & CSAccount & “.”
End If
End If
Next
End Sub