Rogerwa 0 Posted January 31 Share Posted January 31 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: expandcollapse popup$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 post Share on other sites
Nine 1,632 Posted January 31 Share Posted January 31 You cannot omit parameters in AutoIt. You need to provide them all (unless a parameter is optional). “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector GIF Animation (cached) Screen Scraping Link to post Share on other sites
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now