Sign in to follow this  
Followers 0
tbaror

Change Service logon account & password?

1 post in this topic

Hi All,

I am looking into a way to change existing Service logon account & password, my first thought was wmi with following code below but i dont know how to bind to specific service i would like to change.

Please advice also another method would be great.

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"

$OutputTitle = ""
$Output = ""
$OutputTitle &= "Computer: " & $strComputer  & @CRLF
$OutputTitle &= "==========================================" & @CRLF
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Service", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) then
   Local $Object_Flag = 0
   For $objItem In $colItems
      $Object_Flag = 1
      $Output &= "AcceptPause: " & $objItem.AcceptPause & @CRLF
      $Output &= "AcceptStop: " & $objItem.AcceptStop & @CRLF
      $Output &= "Caption: " & $objItem.Caption & @CRLF
      $Output &= "CheckPoint: " & $objItem.CheckPoint & @CRLF
      $Output &= "CreationClassName: " & $objItem.CreationClassName & @CRLF
      $Output &= "Description: " & $objItem.Description & @CRLF
      $Output &= "DesktopInteract: " & $objItem.DesktopInteract & @CRLF
      $Output &= "DisplayName: " & $objItem.DisplayName & @CRLF
      $Output &= "ErrorControl: " & $objItem.ErrorControl & @CRLF
      $Output &= "ExitCode: " & $objItem.ExitCode & @CRLF
      $Output &= "InstallDate: " & WMIDateStringToDate($objItem.InstallDate) & @CRLF
      $Output &= "Name: " & $objItem.Name & @CRLF
      $Output &= "PathName: " & $objItem.PathName & @CRLF
      $Output &= "ProcessId: " & $objItem.ProcessId & @CRLF
      $Output &= "ServiceSpecificExitCode: " & $objItem.ServiceSpecificExitCode & @CRLF
      $Output &= "ServiceType: " & $objItem.ServiceType & @CRLF
      $Output &= "Started: " & $objItem.Started & @CRLF
      $Output &= "StartMode: " & $objItem.StartMode & @CRLF
      $Output &= "StartName: " & $objItem.StartName & @CRLF
      $Output &= "State: " & $objItem.State & @CRLF
      $Output &= "Status: " & $objItem.Status & @CRLF
      $Output &= "SystemCreationClassName: " & $objItem.SystemCreationClassName & @CRLF
      $Output &= "SystemName: " & $objItem.SystemName & @CRLF
      $Output &= "TagId: " & $objItem.TagId & @CRLF
      $Output &= "WaitHint: " & $objItem.WaitHint & @CRLF
      if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop
      $Output=""
   Next
  If $Object_Flag = 0 Then Msgbox(1,"WMI Output",$OutputTitle)
Else
   Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_Service" )
Endif


Func WMIDateStringToDate($dtmDate)
    Return (StringMid($dtmDate, 5, 2) & "/" & _
    StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _
    & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2))
EndFunc

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0