steve8tch Posted May 17, 2005 Posted May 17, 2005 This works - this just changes the caption of the service $strComputer = "localhost" $objWMIService = ObjGet ("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_Service WHERE Caption = 'Error Reporting Service' ") If IsObj ($colItems) Then For $objItem In $colItems $objItem.change("A new caption") Next EndIf This does not work - this tries to change the startup mode of a service. $strComputer = "localhost" $objWMIService = ObjGet ("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_Service WHERE Caption = 'Error Reporting Service' ") If IsObj ($colItems) Then For $objItem In $colItems $objItem.change(, , , , "Manual") Next EndIf It looks like it should work This this the code snipped from MS illustrating the .change method strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & _ strComputer & "\root\cimv2") Set colServiceList = objWMIService.ExecQuery _ ("Select * from Win32_Service where StartMode = 'Manual'") For Each objService in colServiceList errReturnCode = objService.Change( , , , , "Disabled") Next Anyone any thoughts ?
SumTingWong Posted May 17, 2005 Posted May 17, 2005 This does not work - this tries to change the startup mode of a service.$strComputer = "localhost" $objWMIService = ObjGet ("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_Service WHERE Caption = 'Error Reporting Service' ") If IsObj ($colItems) Then For $objItem In $colItems $objItem.change(, , , , "Manual") Next EndIfAnyone any thoughts ? <{POST_SNAPBACK}>I don't think you can do this in AutoIT$objItem.change(, , , , "Manual")Have a look here for proper usage of the Change method.
steve8tch Posted May 17, 2005 Author Posted May 17, 2005 Thanks for your reply.Have a look here for proper usage of the Change method.The snippet of code quoted in the first post was referenced from that page !!strComputer = "."Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & _ strComputer & "\root\cimv2")Set colServiceList = objWMIService.ExecQuery _ ("Select * from Win32_Service where StartMode = 'Manual'")For Each objService in colServiceList errReturnCode = objService.Change( , , , , "Disabled") NextI have just got home and run the example code given on first post - at home the code runs - but does not change to startup mode of the service. At work the script errors out pointing to the first (, <----- .Any thoughts ?
SumTingWong Posted May 17, 2005 Posted May 17, 2005 (edited) Thanks for your reply.The snippet of code quoted in the first post was referenced from that page !!I have just got home and run the example code given on first post - at home the code runs - but does not change to startup mode of the service. At work the script errors out pointing to the first (, <----- .Any thoughts ? <{POST_SNAPBACK}>If you just want to change the start mode then you can use the ChangeStartMode method.Otherwise, I think you will have to fill in all the params prior to StartMode using the service's built-in properties.Here's how you can get to those properties:$strComputer = @ComputerName $objWMIService = ObjGet ("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_Service WHERE Caption = 'Error Reporting Service' ") If IsObj ($colItems) Then For $objItem In $colItems ConsoleWrite($objItem.DisplayName & @LF) ConsoleWrite($objItem.PathName & @LF) ConsoleWrite($objItem.ServiceType & @LF) ConsoleWrite($objItem.ErrorControl & @LF) ConsoleWrite($objItem.StartMode & @LF) ConsoleWrite($objItem.DesktopInteract & @LF) ConsoleWrite($objItem.StartName & @LF) Next EndIf Edited May 17, 2005 by SumTingWong
SvenP Posted May 17, 2005 Posted May 17, 2005 This does not work - this tries to change the startup mode of a service.... $objItem.change(, , , , "Manual") ...<{POST_SNAPBACK}>Hello steve8tch,Like SumTingWong said: AutoIt does not allow empty parameters to function calls. That's because AutoIt does not have something like a NULL value (the nearest AutoIt can do is an empty string or an integer 0). But since these type of COM-calls occur very often, I added some code that will support empty parameters, but ONLY in COM-functions. I have tested your script with this modified AutoIt3.exe and it works !I will submit the patch to jpm, who will hopefully merge it with the next beta version.Thanks for finding this bug..(nah, not really a bug, more a 'missing feature' :-)Regards,-Sven
steve8tch Posted May 17, 2005 Author Posted May 17, 2005 Both of you - thankyou very much. (I think this is proving an exercise in understanding MSDN as new functionality in Aut3!!!) As you suggested... $strComputer = "localhost" $objWMIService = ObjGet ("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_Service WHERE Caption = 'Error Reporting Service' ") If IsObj ($colItems) Then For $objItem In $colItems $objItem.changeStartMode("Manual") Next EndIf works. I would like to have got the change method to work - just so that I could learn more from it - but after a few failed attempts... I thought that I just leave it for now and post my thanks to you!!
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