Automate a printer installation under Vista or Windows 7
The following script installs a printer on a Windows Vista/Windows 7 workstation ; if a list of printers are stored in a file, the same script can be used for installing multiple printers.
You can find the corresponding script file under Script_Examples, sub-directory of scripts.
'PRINTER INSTALLATION UNDER WINDOWS VISTA OR WINDOWS 7
'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$)
'Invoke the File menu where Add Printer option is displayed.
'We call the File menu using the Alt+F keyboard shortcut.
UseWindow("EXPLORER.EXE|ShellTabWindowClass|Printers",1)
SendKeys("<Alt F>")
UseWindow("EXPLORER.EXE|ShellTabWindowClass|Printers",1)
ChooseMenu(Context,"Add &Printer...")
'On Add Printer screen, select Add a local Printer using the l shortcut
UseWindow("EXPLORER.EXE|CtrlNotifySink|Add Printer|1",1)
'On Add Printer next screen, Choose a printer port, click Next button
UseWindow("EXPLORER.EXE|CtrlNotifySink|Add Printer|1",1)
Click(Button,"&Next")
'Select Generic and Text / Only
UseWindow("EXPLORER.EXE|#32770|Add Printer|5",1)
ChooseItem(ListView, "1", "Generic", single, left )
ChooseItem(ListView, "3", "Generic / Text Only", single, left )
'And click Next
UseWindow("EXPLORER.EXE|CtrlNotifySink|Add Printer|1",1)
Click(Button,"&Next")
'Give the name you have specified to the printer that you add.
UseWindow("EXPLORER.EXE|Edit|Add Printer|2",1, NoActivate)
SendKeys(var$)
'And click Next
UseWindow("EXPLORER.EXE|CtrlNotifySink|Add Printer|1",1)
Click(Button,"&Next")
''SYNCHRONIZATION : wait until "You " from You've successfully added sentence is there.
Pause 20 secs until
Text("You")
InWindow("EXPLORER.EXE|DirectUIHWND|Add Printer|1",1)
PauseFalse
MsgBox("'Wait for' at line " + #ErrorLine$ + " has failed !")
End
EndPause
'Click Finish
UseWindow("EXPLORER.EXE|CtrlNotifySink|Add Printer|2",1)
Click(Button,"&Finish")
'Close the printers window.
CloseWindow("EXPLORER.EXE|CabinetWClass|Printers",1)
'The printer has been added