Automate a printer installation

The following script installs a printer on a Windows XP workstation ; if a list of printers are stored in a file, the same script can be used for installing multiple printers. For other Windows version, window names can be slightly different but the same kind of automation can be used.

 

'PRINTER INSTALLATION UNDER WINDOWS XP

 

'Give here the printer name you want to add,

'or you can read the printer names from a file.

var$="My printer"

 

'run the printer configuration tool

lgncmde$="control printers"

shell(lgncmde$)

 

'SYNCHRONIZATION : wait until printers window is displayed

Pause until

WinStatus(Active, Exact)

InWindow("EXPLORER.EXE|SysListView32|Printers and Faxes|1")

PauseFalse

MsgBox("'Wait for' at line " + #ErrorLine$ + " has failed !",16,"Runtime error")

End

EndPause

 

'Select Add printer

UseWindow("EXPLORER.EXE|SHELLDLL_DefView|Printers|1",1)

ChooseItem(ListView, "1", "Add Printer", double, left )

 

'SYNCHRONIZATION : wait until Add printer wizard window is displayed

Pause until

WinStatus(Active, Exact)

InWindow("EXPLORER.EXE|#32770|Add Printer Wizard")

PauseFalse

MsgBox("'Wait for' at line " + #ErrorLine$ + " has failed !",16,"Runtime error")

End

EndPause

 

 

'click Next

UseWindow("EXPLORER.EXE|#32770|Add Printer Wizard",1)

Click(Button,"&Next >")

 

'SYNCHRONIZATION : wait until Local or Network Printer text is displayed

'in the same window Add printer Wizard

Pause until

Text("Local or Network Printer")

InWindow("EXPLORER.EXE|#32770|Add Printer Wizard",1)

PauseFalse

MsgBox("'Wait for' at line " + #ErrorLine$ + " has failed !",16,"Runtime error")

End

EndPause

 

 

'check Local printer and Do not automatically detect

UseWindow("EXPLORER.EXE|#32770|Add Printer Wizard|1",1)

Click(Radio,"&Local printer")

Click(Check,"&Automatically detect and install my Plug and Play printer",OFF)

UseWindow("EXPLORER.EXE|#32770|Add Printer Wizard",1)

Click(Button,"&Next >")

 

'SYNCHRONIZATION : wait until Select the Printer Port text appears in the Wizard window

Pause until

Text("Select a Printer Port")

InWindow("EXPLORER.EXE|#32770|Add Printer Wizard",1)

PauseFalse

MsgBox("'Wait for' at line " + #ErrorLine$ + " has failed !",16,"Runtime error")

End

EndPause

 

'Selected default port is OK, so just click Next

UseWindow("EXPLORER.EXE|#32770|Add Printer Wizard",1)

Click(Button,"&Next >")

 

'SYNCHRONIZATION : Windows builds its list of all printers

'wait until The manufacturer and model text is displayed in Wizard window

Pause until

Text("The manufacturer and model determine which printer software to use.")

InWindow("EXPLORER.EXE|#32770|Add Printer Wizard",1)

PauseFalse

MsgBox("'Wait for' at line " + #ErrorLine$ + " has failed !",16,"Runtime error")

End

EndPause

 

 

'Select Generic and Text / Only

UseWindow("EXPLORER.EXE|#32770|Add Printer Wizard|1",1)

ChooseItem(ListView, "1", "Generic", single, left )

pause 1

ChooseItem(ListView, "3", "Generic / Text Only", single, left )

pause 1

UseWindow("EXPLORER.EXE|#32770|Add Printer Wizard",1)

Click(Button,"&Next >")

 

 

'SYNCHRONIZATION : wait until Use Existing Driver text is displayed

'ATTENTION : as this window does not exist if no driver has been installed

'We limit the Pause to 10 seconds and we don't generate an error if the window is not found

Pause 10 until

Text("Use Existing Driver")

InWindow("EXPLORER.EXE|#32770|Add Printer Wizard",1)

PauseOk

'Select Keep existing driver

UseWindow("EXPLORER.EXE|#32770|Add Printer Wizard|1",1)

Click(Radio,"&Keep existing driver (recommended)")

Click(Button,"&Next >")

EndPause

 

'SYNCHRONIZATION

Pause until

Text("Name Your Printer")

InWindow("EXPLORER.EXE|#32770|Add Printer Wizard",1)

PauseFalse

MsgBox("'Wait for' at line " + #ErrorLine$ + " has failed !",16,"Runtime error")

End

EndPause

 

 

'Type the printer name

UseWindow("EXPLORER.EXE|#32770|Add Printer Wizard|1",1)

WriteEdit("1",var$)

pause 1

 

'Select Not the default printer

Click(Radio,"N&o")

Click(Button,"&Next >")

 

'SYNCHRONIZATION

Pause until

Text("Printer Sharing")

InWindow("EXPLORER.EXE|#32770|Add Printer Wizard",1)

PauseFalse

MsgBox("'Wait for' at line " + #ErrorLine$ + " has failed !",16,"Runtime error")

End

EndPause

 

'Select Do not share this printer

UseWindow("EXPLORER.EXE|#32770|Add Printer Wizard|1",1)

Click(Radio,"D&o not share this printer")

Pause 1

Click(Button,"&Next >")

 

'SYNCHRONIZATION

Pause until

Text("Print Test Page")

InWindow("EXPLORER.EXE|#32770|Add Printer Wizard",1)

PauseFalse

MsgBox("'Wait for' at line " + #ErrorLine$ + " has failed !",16,"Runtime error")

End

EndPause

 

'Select No

UseWindow("EXPLORER.EXE|#32770|Add Printer Wizard|1",1)

Click(Radio,"N&o|1")

Click(Button,"&Next >")

 

'SYNCHRONIZATION : wait until Completing window is displayed

Pause until

WinStatus(Exists, Exact)

InWindow("EXPLORER.EXE|Static|Completing the Add Printer Wizard",1)

PauseFalse

MsgBox("'Wait for' at line " + #ErrorLine$ + " has failed !",16,"Runtime error")

End

EndPause

 

 

UseWindow("EXPLORER.EXE|#32770|Add Printer Wizard",1)

Click(Button,"Finish")

 

 

'SYNCHRONIZATION : wait until Wizard window disappears

Pause until

WinStatus(NotExists, Exact)

InWindow("EXPLORER.EXE|#32770|Add Printer Wizard|1")

PauseFalse

MsgBox("'Wait for' at line " + #ErrorLine$ + " has failed !",16,"Runtime error")

End

EndPause

 

Pause 2

 

CloseWindow("EXPLORER.EXE|CabinetWClass|Printers",1)

 

 

'The printer has been added