'*********************************************************** '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 '*********************************************************** Option Explicit Dim shellobj,env Dim strUserDomain,strUserName,strPassword,strComputer Dim CSComputerName,CSAccount,CSPassword,objWMIService Dim objService 'Check to make sure that we receive enough arguements (2 or more) 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") 'Setup default domain for credentials '(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) 'Setup a WMIService object, and setup a query to put all services in an array Set objWMIService = GetObject("winmgmts:\\" & CSComputerName & "\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * from Win32_Service",,48) 'Loop through the array For Each objService in colItems 'If the "Logon As" of the current service matches the user specified, '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