Jump to content

VBScript Conversion to Autoit Change Windows Service Password


Rogerwa
 Share

Recommended Posts

I am attempting to convert a vbscript to autoit.  The vbscript is below:

strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\Root\CIMv2")
Set colServiceList = objWMIService.ExecQuery("SELECT * FROM Win32_Service WHERE StartName = '.\\NetSvc'")
For Each objService in colServices
 errServiceChange = objService.Change( , , , , , ,  , "Test.123")
Next

 

I am having a time with the following line:

errServiceChange = objService.Change( , , , , , , , "TEST.123")

 

My autoit code is below and throws a syntax error in autoit.  I have included the conversion code I wrote.  I have attempted to put quotes between each comma but that still throws com errors and will not change the service password.  I am just not sure how to represent the code in autoit to prevent the syntax error and get it to work.  See below for the autoit syntax I wrote:

$oMyError = ObjEvent ("AutoIt.Error", "MyErrFunc")
$ServiceAccounts = @LF
$password = ""

$serviceUserName = InputBox("Service Account Password Change", "Enter service account you want to change password on." & @LF & @LF & "NOTE:  Enter in the form of domain\\useraccount.  Double back slashes are required.  Enter local account as .\\useraccount.", "", "", 350, 200)
If @error = 1 Then
    MsgBox(64, "Serivce Account Password Change", "Password change canceled.")
    Exit
EndIf
$password = InputBox("Service Account Password Change", "Enter password for service account.", "")
If @error = 1 Then
    MsgBox(64, "Serivce Account Password Change", "Password change canceled.")
    Exit
EndIf
$strComputer = "."
$objWMIService = ObjGet("winmgmts:" & "{impersonationLevel=impersonate}!\\" & $strComputer)
$colServiceList = $objWMIService.ExecQuery("Select * from Win32_Service where StartName like '" & $serviceUserName & "'")
For $objService in $colServiceList)
    $objService.Change( , , , , , , , "Test.123")
    $ServiceAccounts = $ServiceAccounts & $objService.DisplayName & @LF
Next

MsgBox(64, "Service Account Password Change", "The following service accounts need to be restarted:" & @LF & $ServiceAccounts)

Func MyErrFunc()

  Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !"      & @CRLF  & @CRLF & _
             "err.description is: "    & @TAB & $oMyError.description    & @CRLF & _
             "err.windescription:"     & @TAB & $oMyError.windescription & @CRLF & _
             "err.number is: "         & @TAB & hex($oMyError.number,8)  & @CRLF & _
             "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
             "err.scriptline is: "     & @TAB & $oMyError.scriptline     & @CRLF & _
             "err.source is: "         & @TAB & $oMyError.source         & @CRLF & _
             "err.helpfile is: "       & @TAB & $oMyError.helpfile       & @CRLF & _
             "err.helpcontext is: "    & @TAB & $oMyError.helpcontext _
            )

    Local $err = $oMyError.number
    If $err = 0 Then $err = -1

    $g_eventerror = $err  ; to check for after this function returns
Endfunc

Note that I did not use the $password variable but I would put that were the Test.123 is.  I omitted the $password variable for the test password just to see if I could get the script to run.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...