ECHAIGNE Posted November 15, 2006 Share Posted November 15, 2006 Hi I try to remove all the printers drivers not used. The 1st and 3éme lines lists the whole of the printers drivers installed on the computer. The 2éme line call the function with a parameter of request for suppression and, systematically, the request for suppression fails without call the error function, in the line $ObjItem.delete_ and stop the program with a error not intercepted by AutoIt.error : The requested action with this object has failed The same script in VBS work properly and the error is intercepted by On Error Resume Next. PS : I also to note similar behavior in requests AD at the time of the call to certain properties of object (owner of a list of distribution nonwell informed, for example) A idea ? Const $Supprime = 1 PiloteImprimantes() PiloteImprimantes($Supprime) PiloteImprimantes() Func PiloteImprimantes($Delete = 0) Const $wbemFlagReturnImmediately = 0x10 Const $wbemFlagForwardOnly = 0x20 Const $strComputer = "localhost" Local $objWMIService, $colItems = "", $objItem $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") If IsObj($objWMIService) Then $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_PrinterDriver", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) Then For $objItem In $colItems If $Delete Then $oMyError = ObjEvent("AutoIt.Error", "ComError") $objItem.Delete_ ; Failed here, stops the program even with the call to the management of error Else MsgBox(4096, "Pilotes Imprimantes", $objItem.Name) EndIf Next EndIf EndIf EndFunc ;==>PiloteImprimantes Func ComError() Local $HexNumber If IsObj($oMyError) Then $HexNumber = Hex($oMyError.number, 8) If Not @Compiled Then MsgBox(0, "AutoItCOM", "Une erreur COM a été intercepté !" & @CRLF & @CRLF & _ "Description : " & @TAB & $oMyError.description & @CRLF & _ "Description Windows : " & $oMyError.windescription & @CRLF & _ "Numéro : " & @TAB & $HexNumber & @CRLF & _ "Ligne : " & @TAB & $oMyError.scriptline & @CRLF, 10) EndIf SetError($HexNumber) EndIf SetError(1) Return 0 EndFunc ;==>ComError Thanks you for your answer Eric CHAIGNE Link to comment Share on other sites More sharing options...
MHz Posted November 15, 2006 Share Posted November 15, 2006 A local variable cannot be seen in another function so it needs to be Global.Global $oMyError = ObjEvent("AutoIt.Error", "ComError")Honestly a support question . Link to comment Share on other sites More sharing options...
ECHAIGNE Posted November 15, 2006 Author Share Posted November 15, 2006 A local variable cannot be seen in another function so it needs to be Global.Global $oMyError = ObjEvent("AutoIt.Error", "ComError")Honestly a support question .Afflicted, I forgot the 1st line : Global $oMyErrorThe variable is quite Global and the problem remains the same one Link to comment Share on other sites More sharing options...
Developers Jos Posted November 15, 2006 Developers Share Posted November 15, 2006 try moving this line to the top of the script that it only runs one time .... $oMyError = ObjEvent("AutoIt.Error", "ComError") SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
MHz Posted November 15, 2006 Share Posted November 15, 2006 Having some issues finding a script similar to posted, but this knocks out my printer without problem and uses same object.delete_ line. Global $oMyError = ObjEvent("AutoIt.Error", "ComError") $strComputer = "." $objWMIService = ObjGet("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2") $colInstalledPrinters = $objWMIService.ExecQuery _ ("Select * from Win32_Printer where DeviceID = 'Printer'") For $objPrinter in $colInstalledPrinters $objPrinter.Delete_ Next Func ComError() Local $HexNumber If IsObj($oMyError) Then $HexNumber = Hex($oMyError.number, 8) If Not @Compiled Then MsgBox(0, "AutoItCOM", "Une erreur COM a été intercepté !" & @CRLF & @CRLF & _ "Description : " & @TAB & $oMyError.description & @CRLF & _ "Description Windows : " & $oMyError.windescription & @CRLF & _ "Numéro : " & @TAB & $HexNumber & @CRLF & _ "Ligne : " & @TAB & $oMyError.scriptline & @CRLF, 10) EndIf SetError($HexNumber) EndIf SetError(1) Return 0 EndFunc ;==>ComError Have you got your working VBScript version to view? Link to comment Share on other sites More sharing options...
ECHAIGNE Posted November 15, 2006 Author Share Posted November 15, 2006 try moving this line to the top of the script that it only runs one time .... $oMyError = ObjEvent("AutoIt.Error", "ComError") I had not thought of testing this easy way. It functions, except in the case or one uses Global $oMyError = ObjEvent (AutoIt.Error, Nothing) instead of Global $oMyError = ObjEvent (AutoIt.Error, ComError) Thank you very much, I could make function several fonctionnalitées who posed problems of error to me Link to comment Share on other sites More sharing options...
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