Jump to content

Deleting multiple printers


Recommended Posts

Hello,

I have ran into a rather unique problem at my job. I have installed 4 brother MFC240C printers into 4 communication trailers. I have also installed the drivers to this printer on 8 different laptops. The workers that have the laptops transfer from trailer to trailer and plug into the printers via USB. Problem is when they switch trailers the default printer stays as the brother printer from the first trailer. They are seen as 4 separate printers even though they are of the same type. It makes a copy of the printer in the printer file each time they plug into one of the printers that they have never plugged into before.

The problem is these guys are from lets just say an older generation. They don't want to know about pull down menu's and which printer is the default printer. They just want to print. I have just started trying autoit and have not got a whole lot of experience. I was wondering if someone might show me a script that would go in and delete all printers with the "Brother" name out of the "printers and faxes" folder in Windows XP. That way they could just double click the script and then plug in their usb (the brother printers are the only ones installed.) Any help on this issue would be greatly appreciated.

Downst8

Link to comment
Share on other sites

Hello,

I have ran into a rather unique problem at my job. I have installed 4 brother MFC240C printers into 4 communication trailers. I have also installed the drivers to this printer on 8 different laptops. The workers that have the laptops transfer from trailer to trailer and plug into the printers via USB. Problem is when they switch trailers the default printer stays as the brother printer from the first trailer. They are seen as 4 separate printers even though they are of the same type. It makes a copy of the printer in the printer file each time they plug into one of the printers that they have never plugged into before.

The problem is these guys are from lets just say an older generation. They don't want to know about pull down menu's and which printer is the default printer. They just want to print. I have just started trying autoit and have not got a whole lot of experience. I was wondering if someone might show me a script that would go in and delete all printers with the "Brother" name out of the "printers and faxes" folder in Windows XP. That way they could just double click the script and then plug in their usb (the brother printers are the only ones installed.) Any help on this issue would be greatly appreciated.

Downst8

Welcome to the forum. Grab a copy of Auto3Lib from my signature and try this:

#include <A3LListView.au3>
#include <A3LMenu.au3>

Opt("MustDeclareVars", 1)

Global $hList, $iIndex, $iCount

; Open "Printer and Faxes" folder
Run("RunDll32.exe Shell32.dll,SHHelpShortcuts_RunDLL PrintersFolder")
_Lib_WinWaitActive("Printers and Faxes")

; Get the handle to the ListView control
$hList = ControlGetHandle("Printers and Faxes", "", "SysListView321")
if $hList = 0 then _Lib_ShowError("Unable to get ListView handle")

; Get the number of printers
$iCount = _ListView_GetItemCount($hList)
$iIndex = 0

; Delete any printer with "Brother" in the description
while $iIndex < $iCount
  if StringInStr(_ListView_GetItemText($hList, $iIndex), "Brother") then
    ; Right click on the printer
    _ListView_ClickItem($hList, $iIndex, "right")
    ; Select the "Delete" menu item from popup
    _Menu_ClickPopupAccel("D")
    ; Wait for confirmation dialog to appear
    WinWaitActive("Printers", "Are you sure you want to delete")
    ; Press "Yes" button
    ControlClick("Printers", "Are you sure you want to delete", "Yes")
    ; Reset printer count
    $iCount = _ListView_GetItemCount($hList)
  else
    $iIndex += 1
  endif
wend

It's not tested as I don't have any Brother printers, but it should be close to what you want. If you have any problems, feel free to PM me.

Edit: Fixed small bug

Edited by PaulIA
Auto3Lib: A library of over 1200 functions for AutoIt
Link to comment
Share on other sites

Welcome to the forum. Grab a copy of Auto3Lib from my signature and try this:

#include <A3LListView.au3>
#include <A3LMenu.au3>

Opt("MustDeclareVars", 1)

Global $hList, $iIndex, $iCount

; Open "Printer and Faxes" folder
Run("RunDll32.exe Shell32.dll,SHHelpShortcuts_RunDLL PrintersFolder")
_Lib_WinWaitActive("Printers and Faxes")

; Get the handle to the ListView control
$hList = ControlGetHandle("Printers and Faxes", "", "SysListView321")
if $hList = 0 then _Lib_ShowError("Unable to get ListView handle")

; Get the number of printers
$iCount = _ListView_GetItemCount($hList)
$iIndex = 0

; Delete any printer with "Brother" in the description
while $iIndex < $iCount
  if StringInStr(_ListView_GetItemText($hList, $iIndex), "Brother") then
    ; Right click on the printer
    _ListView_ClickItem($hList, $iIndex, "right")
    ; Select the "Delete" menu item from popup
    _Menu_ClickPopupAccel("D")
    ; Wait for confirmation dialog to appear
    WinWaitActive("Printers", "Are you sure you want to delete")
    ; Press "Yes" button
    ControlClick("Printers", "Are you sure you want to delete", "Yes")
    ; Reset printer count
    $iCount = _ListView_GetItemCount($hList)
  endif
  $iIndex += 1
wend

It's not tested as I don't have any Brother printers, but it should be close to what you want. If you have any problems, feel free to PM me.

Thank you very much. I will try it first thing in the morning and let you know. I really appreciate it. Thank you for the welcome and I look forward to learning Au3 and being a part of this community.

Downst8

Link to comment
Share on other sites

Thank you very much. I will try it first thing in the morning and let you know. I really appreciate it. Thank you for the welcome and I look forward to learning Au3 and being a part of this community.

Downst8

You're welcome. The script has a small bug. Use this one instead:

#include <A3LListView.au3>
#include <A3LMenu.au3>

Opt("MustDeclareVars", 1)

Global $hList, $iIndex, $iCount

; Open "Printer and Faxes" folder
Run("RunDll32.exe Shell32.dll,SHHelpShortcuts_RunDLL PrintersFolder")
_Lib_WinWaitActive("Printers and Faxes")

; Get the handle to the ListView control
$hList = ControlGetHandle("Printers and Faxes", "", "SysListView321")
if $hList = 0 then _Lib_ShowError("Unable to get ListView handle")

; Get the number of printers
$iCount = _ListView_GetItemCount($hList)
$iIndex = 0

; Delete any printer with "Brother" in the description
while $iIndex < $iCount
  if StringInStr(_ListView_GetItemText($hList, $iIndex), "Brother") then
    ; Right click on the printer
    _ListView_ClickItem($hList, $iIndex, "right")
    ; Select the "Delete" menu item from popup
    _Menu_ClickPopupAccel("D")
    ; Wait for confirmation dialog to appear
    WinWaitActive("Printers", "Are you sure you want to delete")
    ; Press "Yes" button
    ControlClick("Printers", "Are you sure you want to delete", "Yes")
    ; Reset printer count
    $iCount = _ListView_GetItemCount($hList)
  else
    $iIndex += 1
  endif
wend
Auto3Lib: A library of over 1200 functions for AutoIt
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...