ECHAIGNE Posted November 10, 2006 Share Posted November 10, 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 is supposed appeller the function with a parameter of request for suppression and, systematically, the request for suppression fails. 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 Eric Link to comment Share on other sites More sharing options...
lod3n Posted November 10, 2006 Share Posted November 10, 2006 As per this article:http://www.microsoft.com/technet/scriptcen...05/hey1201.mspxThe Delete_ method only works on Windows XP and later.Personally, I get a lot more satisfaction out of printui.dllhttp://www.robvanderwoude.com/2kprintcontrol.html [font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font] Link to comment Share on other sites More sharing options...
ECHAIGNE Posted November 10, 2006 Author Share Posted November 10, 2006 As per this article:http://www.microsoft.com/technet/scriptcen...05/hey1201.mspxThe Delete_ method only works on Windows XP and later.Personally, I get a lot more satisfaction out of printui.dllhttp://www.robvanderwoude.com/2kprintcontrol.htmlThanks for your answerMy script is for Windows XP.A similar code in VBS works (seee %Systemroot%\System32\PrnDrv.vbs)I have make a version vith RUNDLL32 PRINTUI.DLL and option /dd. It's work but it is necessary to manage the windows of nonremoval of the pilots used. I find this not very cleanBye 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