JJordan Posted April 6, 2011 Share Posted April 6, 2011 (edited) Hello, I am attempting to write an AutoIT script to install printers by IP address for WinXP SP3 only. I am hitting two road blocks so far. 1. If the printer is offline, an additional dialog box appears. "The device could not be found on the network". How do I properly handle this dialog? This window takes several seconds to appear and I attempted to put a sleep timer in to wait for this additional dialog to appear. I also attempt to use the Window info tool to identify this dialog, but it appears all of the printer wizard dialogs are identical. 2. If the TCP/IP printer port exists, it prompts a dialog "A port with that name already exists." How would I check for an existing TCP/IP port before running the printer install wizard? Thanks, Jordan Here is what I have for the code so far expandcollapse popup#cs ---------------------------------------------------------------------------- Author: WiSp Organization: ** Removed ** Script Function: Automatically install the Canon and Ricoh series printers. Models Covered: #ce ---------------------------------------------------------------------------- ; Script Start #Include <GuiListView.au3> #include <GUIConstants.au3> ;#NoTrayIcon Dim $PrinterDriver = "" Dim $IPAddress = "" Dim $PrinterModel = "" Dim $PrinterFriendlyName = "" Dim $PrinterFriendlyNameAndIP = "" Dim $PrinterMakeDefault = "0" Dim $PrinterChoice = "" ;---------Drivers List------------------ Dim $Printer1 = "C:\Printerdrivers\Canon Printer-Copiers\win2k_xp\pcl5e_5c\P52KUSAL.INF" ; Check to see if the OS it's being run on is Windows 2K or Windows XP, all others fail. ;$OSVer = @OSVersion ;If $OSVer <> "Win_XP" Then ; If $OSVer <> "Win_2000" Then ; MsgBox (48, "Wrong OS Version", "Sorry, you are running " & $OSVer & ", this program is for Windows 2000 or XP only.") ; Exit ; EndIf ;EndIf #Region ### START GUI section ### $Form1_1 = GUICreate("Printer Installer", 211, 217, -1, -1) $List1 = GUICtrlCreateList("", 8, 72, 193, 97) ; NOTE: The list is the actualy driver name as it would be found if you were selecting it from a list of drivers. ; It is trimmed later to make the name more friendly Dim $PrinterChoice = GUICtrlSetData(-1, "Printer1") $Button1 = GUICtrlCreateButton("&Install Printer", 8, 184, 121, 25, 0) $Button2 = GUICtrlCreateButton("&Cancel", 136, 184, 65, 25, 0) $Label1 = GUICtrlCreateLabel($PrinterChoice, 8, 8, 91, 17) $Label2 = GUICtrlCreateLabel("Select Printer Model:", 8, 56, 102, 17) GUISetState(@SW_SHOW) #EndRegion ### END GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg ;Select Case $Button1 $Printerchoice = GUICtrlRead ( 3 ) MsgBox(0, "", "You selected "&$Printerchoice, 2) If StringInStr($PrinterChoice, "Printer1") Then $PrinterModel = "Canon iR5000 PCL6" ; Driver name found in the .ini $PrinterDriver = $Printer1 $IPAddress = String("10.8.66.25") EndIf GUISetState(@SW_HIDE) ExitLoop Case $Button2; Cancel button Exit Case $GUI_EVENT_CLOSE; Windows "X" button Exit ;EndSelect EndSwitch WEnd ; Run the Add Printer Wizard Run(@ComSpec & " /c " & 'rundll32 printui.dll,PrintUIEntry /il', "",@SW_HIDE) ;If $OSVer = "WIN_XP" Then WinWaitActive ("Add Printer Wizard", "Welcome to the Add Printer Wizard") ControlClick ("Add Printer Wizard", "", 12324); Click Next> WinWaitActive ("Add Printer Wizard", "Select the option that describes the printer you want to use") ControlClick ("Add Printer Wizard", "", 3510); Select Local Pritner ControlCommand ("Add Printer Wizard", "Automatically detect and install my Plug and Play printer", 4665, "UnCheck"); Uncheck AutoDetect ControlClick ("Add Printer Wizard", "Select the option that describes the printer you want to use",12324); Click Next> WinWaitActive ("Add Printer Wizard", "Select the port you want your printer to use") ControlCommand ("Add Printer Wizard", "Create a new port", 4558, "Check", ""); We want to create a new port ControlCommand ("Add Printer Wizard", "Create a new port", 4557, "SelectString", 'Standard TCP/IP Port'); look for Standard TCP/IP port ControlClick ("Add Printer Wizard", "", 12324); Click Next> ; Enter the IP address and Name of the printer, these are taken from variable input boxes at the beginning WinWaitActive( "Add Standard TCP/IP Printer Port Wizard", "You use this wizard to add a port for a network printer") ControlClick ("Add Standard TCP/IP Printer Port Wizard", "", 12324); Click Next> WinWaitActive( "Add Standard TCP/IP Printer Port Wizard", "Enter the Printer Name or IP address") ControlSetText ( "Add Standard TCP/IP Printer Port Wizard", "", 1000, $IPAddress) ControlClick ("Add Standard TCP/IP Printer Port Wizard", "", 12324); Click Next> Sleep(20000) ControlClick ("Add Standard TCP/IP Printer Port Wizard", "", 12324); Click Next> ; Finish off the add _port_ wizard and then return to the add _printer_ wizard WinWaitActive( "Add Standard TCP/IP Printer Port Wizard") ;,"You have selected a port with the following characteristics.") ControlClick ("Add Standard TCP/IP Printer Port Wizard", "", 12325); Click finish button ; Kill the Add Printer wizard, we added our port already, we don't need it this program anymore. ;WinWaitActive( "Add Printer Wizard", "Select the manufacturer and model of your printer") ; ControlClick ( "Add Printer Wizard", "", 2); Click Cancel button ;;; Grand Finale! Install the damn thing! ;RunWait(@ComSpec & " /c " & 'rundll32 printui.dll PrintUIEntry /b "' & $PrinterFriendlyNameAndIP & '" /if /f "' & $PrinterDriver & '" /r "' & $PrinterFriendlyNameAndIP & '" /m "' & $PrinterModel & '"', "",@SW_HIDE) Edited April 6, 2011 by JJordan Link to comment Share on other sites More sharing options...
water Posted April 6, 2011 Share Posted April 6, 2011 (edited) 1. If the printer is offline, an additional dialog box appears. "The device could not be found on the network". How do I properly handle this dialog? This window takes several seconds to appear and I attempted to put a sleep timer in to wait for this additional dialog to appear. I also attempt to use the Window info tool to identify this dialog, but it appears all of the printer wizard dialogs are identical. Use something like $iReturnValue = WinWait("WindowsTitle", "The device could not be found on the network", timeout-in-seconds) in your script to wait for the error message ("WindowsTitle" has to be replaced by the correct title). If the error message doesn't pop up in the specified timeframe, the script goes on and sets $iReturnValue to 0 so you can decide if the error messages showed up or the timeout expired. Edited April 6, 2011 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki  Link to comment Share on other sites More sharing options...
JJordan Posted April 8, 2011 Author Share Posted April 8, 2011 Thanks for the response. Would my code look like something below? Also, do you know how I would check for an existing TCP/IP printer port? ;Check for extra window. This only appears if the printer is offline If $iReturnValue <> 0 then ;Extra error window ControlClick ("Add Standard TCP/IP Printer Port Wizard", "", 12324); Click Next> else ; Finish off the add _port_ wizard and then return to the add _printer_ wizard WinWaitActive( "Add Standard TCP/IP Printer Port Wizard") ;,"You have selected a port with the following characteristics.") ControlClick ("Add Standard TCP/IP Printer Port Wizard", "", 12325); Click finish button Endif Link to comment Share on other sites More sharing options...
water Posted April 8, 2011 Share Posted April 8, 2011 Looks good. Give it a try and report if you get any errors or not the desired result. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki  Link to comment Share on other sites More sharing options...
JJordan Posted April 8, 2011 Author Share Posted April 8, 2011 This works great! Do you know how I would check for an existing printe TCP/IP port? Here is the code WinWaitActive( "Add Standard TCP/IP Printer Port Wizard", "Enter the Printer Name or IP address") ControlSetText ( "Add Standard TCP/IP Printer Port Wizard", "", 1000, $IPAddress) ControlClick ("Add Standard TCP/IP Printer Port Wizard", "", 12324); Click Next> $iReturnValue = WinWait("Add Standard TCP/IP Printer Port Wizard", "Device Type", 18) If $iReturnValue <> 0 then ControlClick ("Add Standard TCP/IP Printer Port Wizard", "", 12324); Click Next> WinWaitActive( "Add Standard TCP/IP Printer Port Wizard", "You have selected a port with the following characteristics.") ControlClick ("Add Standard TCP/IP Printer Port Wizard", "", 12325); Click finish button else ; Finish off the add _port_ wizard and then return to the add _printer_ wizard WinWaitActive( "Add Standard TCP/IP Printer Port Wizard", "You have selected a port with the following characteristics.") ControlClick ("Add Standard TCP/IP Printer Port Wizard", "", 12325); Click finish button Endif Link to comment Share on other sites More sharing options...
water Posted April 8, 2011 Share Posted April 8, 2011 I'm not very experienced in this area. Maybe trancexx can be a starting point. Or search the forum for "port", "TCPIP" or whatever describes your problem. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki  Link to comment Share on other sites More sharing options...
novotny Posted August 10, 2011 Share Posted August 10, 2011 You can use: persist.vbs portmgr.vbs drvmgr.vbs prnmgr.vbs from MS and before need install prnadmin.dll here is batch code, that can be modifed for autoit set DIRECTORY=C:\install set DIRECTORY_DRV=DIR_OF_DRIVERS set DRIVER=DRIVER_NAME set NAME=PRINTER_NAME set PORT=TCPIP_PORT_NAME set FILE_CFG=SETTING.DAT rem register dll (before copy to windir) Regsvr32 /s "%DIRECTORY%\Prnadmin.dll" rem TCP/IP port install cscript "%DIRECTORY%\portmgr.vbs" -a -p %PORT% -h PRINTERIP -t LPR -q QUEE_NAME -md rem Driver install cscript "%DIRECTORY%\drvmgr.vbs" -a -m "%DRIVER%" -p "%DIRECTORY%\%DIRECTORY_DRV%" -i "%DIRECTORY%"\%DIRECTORY_DRV%\oemsetup.inf" rem install printer cscript "%DIRECTORY%\prnmgr.vbs" -a -b "%NAME%" -m "%DRIVER%" -r "%PORT%" rem load settins of printer cscript "%DIRECTORY%\persist.vbs" -r -b "%NAME%" -f "%DIRECTORY%\%FILE_CFG%" -all -resname -resport -resshare pause Link to comment Share on other sites More sharing options...
tazdev Posted April 1, 2012 Share Posted April 1, 2012 For some reason I completely forgot about cscript and was banging my head against the keyboard trying to do it myself. Thank you very much for the reminder! 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