Thursday, 18 June 2015

Change Service Account Password using VBScript

We can easily manage Windows Service through vbscript by using the WMI class Win32_Service. Use the below vbscript code to change service account password.

1. Copy the below vbscript code and paste it in notepad or a VBScript editor.
2. Change the value strService into your own windows service name which you want to reset password.
3. If you want to modify password of a service account in Remote machine, set the Remote computer name in the variable strComputer instead of "." (local machine).
4. Save the file with a .vbs extension, for example: ChangeServicePwd.vbs
5. Double-click the vbscript file (or Run this file from command window) to change the given windows service account password.
Option Explicit
Dim objWMIService, objService,errOut
Dim strService,strComputer
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
For Each objService In objWMIService.ExecQuery("Select * from Win32_Service Where Name = '"&strService&"'")
    errOut = objService.Change( , , , , , , , "password")
  If(errOut=0) Then
     WScript.Echo strService & ": Service account password changed successfully"
     WScript.Echo strService & ": Password change failed. Error code: "& errOut
  End If


No comments:

Post a Comment