Jump to content

Delete inused printer drivers


ECHAIGNE
 Share

Recommended Posts

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

As per this article:

http://www.microsoft.com/technet/scriptcen...05/hey1201.mspx

The Delete_ method only works on Windows XP and later.

Personally, I get a lot more satisfaction out of printui.dll

http://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

As per this article:

http://www.microsoft.com/technet/scriptcen...05/hey1201.mspx

The Delete_ method only works on Windows XP and later.

Personally, I get a lot more satisfaction out of printui.dll

http://www.robvanderwoude.com/2kprintcontrol.html

Thanks for your answer

My 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 clean

Bye

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...