ejbmail Posted July 28, 2007 Share Posted July 28, 2007 I have not be scripting very long and find myself bashing my head to the wall on this one. I hope that someone can help me with the errors I have been receiving on this script. I'm not sure how to have the program continue on error....i.e. if the printer does not exist or some other error that would not apply or halt the installation of the printer. I'm trying to a lot for possibles that may occur. ; Install Printer on Windows XP or Windows 2000 ;Set Variables $OLDPRT = "OKI B6300.236" $OLDPORT = "10.96.59.105" $NEWPRT = "OKI B6300.235" $NEWDRIVER = "OKI B6300(PS)" $NEWINF = "\OKI6300\Opxf3e.inf" $NEWPORT = "10.98.99.235" $COMMENT = "AS/400 ID: XX IP Address: 10.98.99.235" Dim $oMaster Dim $oPrinter Dim $oDriver Dim $oPrint Dim $oPort $oMaster = ObjCreate("PrintMaster.PrintMaster.1") $oPrint = ObjCreate("PrintMaster.PrintMaster.1") $oPrinter= ObjCreate("Printer.Printer.1") $oDriver = ObjCreate("Driver.Driver.1") $oPrint = ObjCreate("Print.Print.1") $oPort = ObjCreate("Port.Port.1") ;Copy Files for Project FileCopy(@ScriptDir & "\PrnAdmin\*.*", "c:\windows\system32\",1) FileCopy(@ScriptDir & "\JWalkPrintClient\Jw9p.*", "c:\windows\",1) FileDelete("c:\documents and settings\shopuser\desktop\Start Print Screen Client.url") ;Reguster the Dll RunWait("Regsvr32 /s c:\windows\system32\Prnadmin.dll") If FileExists("C:\Documents and Settings\Shopuser") Then RunWait(@ScriptDir & "\Shopupdate.exe /s /qn") EndIf ;Purge Old Printers $oMaster.PrinterPurge ("" & $OLDPRT) $oMaster.PrinterPurge ("" & $NEWPRT) Sleep(10000) ;Delete Old Printers $oMaster.PrinterDel("", $OLDPRT) $oMaster.PrinterDel("", $NEWPRT) $oMaster.PortDel("", $OLDPORT) $oMaster.PortDel("", $NEWPORT) ;Install Port $oPort.ServerName = "" $oPort.PortName = $NEWPRT $oPort.PortType = 1 $oPort.HostAddress = $NEWPORT $oPort.PortNumber = 9100 $oPort.SNMP = True $oPort.SnmpDeviceIndex = 1 $oPort.CommunityName = "public" $oMaster.PortAdd ($oPort) ;Install Driver $oDriver.ServerName = "" $oDriver.ModelName = $NEWDRIVER $oDriver.DriverArchitecture = "Intel" $oDriver.DriverVersion = "Windows 2000, Windows XP and Windows Server 2003" $oDriver.Path = @ScriptDir $oDriver.InfFile = $NEWINF $oMaster.DriverAdd ($oDriver) ;Install Printer $oPrinter.ServerName = "" $oPrinter.PrinterName = $NEWPRT $oPrinter.DriverName = $NEWDRIVER $oPrinter.PortName = $NEWPORT $oPrinter.INFFile = @ScriptDir & $NEWINF $oPrinter.Comment = $COMMENT $oMaster.PrinterAdd ($oPrinter) ;Set Default Printer $oPrint.DefaultPrinter = $NEWPRT RunWait(@ScriptDir & "\OKI6300\okib6300Config.vbs") ;****Completed**** ANY HELP WOULD BE GREAT.......... Link to comment Share on other sites More sharing options...
ejbmail Posted July 30, 2007 Author Share Posted July 30, 2007 I changed my Variables to Global and still I can't reuse the Variables.I still can't figure this out!!!!!!!!!!!!!!!!!!!!!I have not be scripting very long and find myself bashing my head to the wall on this one. I hope that someone can help me with the errors I have been receiving on this script. I'm not sure how to have the program continue on error....i.e. if the printer does not exist or some other error that would not apply or halt the installation of the printer. I'm trying to a lot for possibles that may occur.; Install Printer on Windows XP or Windows 2000;Set Variables$OLDPRT = "OKI B6300.236"$OLDPORT = "10.96.59.105"$NEWPRT = "OKI B6300.235"$NEWDRIVER = "OKI B6300(PS)"$NEWINF = "\OKI6300\Opxf3e.inf"$NEWPORT = "10.98.99.235"$COMMENT = "AS/400 ID: XX IP Address: 10.98.99.235"Dim $oMasterDim $oPrinterDim $oDriverDim $oPrintDim $oPort$oMaster = ObjCreate("PrintMaster.PrintMaster.1")$oPrint = ObjCreate("PrintMaster.PrintMaster.1")$oPrinter= ObjCreate("Printer.Printer.1")$oDriver = ObjCreate("Driver.Driver.1")$oPrint = ObjCreate("Print.Print.1")$oPort = ObjCreate("Port.Port.1");Copy Files for ProjectFileCopy(@ScriptDir & "\PrnAdmin\*.*", "c:\windows\system32\",1)FileCopy(@ScriptDir & "\JWalkPrintClient\Jw9p.*", "c:\windows\",1)FileDelete("c:\documents and settings\shopuser\desktop\Start Print Screen Client.url");Reguster the DllRunWait("Regsvr32 /s c:\windows\system32\Prnadmin.dll")If FileExists("C:\Documents and Settings\Shopuser") Then RunWait(@ScriptDir & "\Shopupdate.exe /s /qn")EndIf;Purge Old Printers$oMaster.PrinterPurge ("" & $OLDPRT)$oMaster.PrinterPurge ("" & $NEWPRT)Sleep(10000);Delete Old Printers$oMaster.PrinterDel("", $OLDPRT)$oMaster.PrinterDel("", $NEWPRT)$oMaster.PortDel("", $OLDPORT)$oMaster.PortDel("", $NEWPORT);Install Port$oPort.ServerName = ""$oPort.PortName = $NEWPRT$oPort.PortType = 1$oPort.HostAddress = $NEWPORT$oPort.PortNumber = 9100$oPort.SNMP = True$oPort.SnmpDeviceIndex = 1$oPort.CommunityName = "public"$oMaster.PortAdd ($oPort);Install Driver$oDriver.ServerName = ""$oDriver.ModelName = $NEWDRIVER$oDriver.DriverArchitecture = "Intel"$oDriver.DriverVersion = "Windows 2000, Windows XP and Windows Server 2003"$oDriver.Path = @ScriptDir$oDriver.InfFile = $NEWINF$oMaster.DriverAdd ($oDriver);Install Printer$oPrinter.ServerName = ""$oPrinter.PrinterName = $NEWPRT$oPrinter.DriverName = $NEWDRIVER$oPrinter.PortName = $NEWPORT$oPrinter.INFFile = @ScriptDir & $NEWINF$oPrinter.Comment = $COMMENT$oMaster.PrinterAdd ($oPrinter);Set Default Printer$oPrint.DefaultPrinter = $NEWPRTRunWait(@ScriptDir & "\OKI6300\okib6300Config.vbs");****Completed****ANY HELP WOULD BE GREAT.......... Link to comment Share on other sites More sharing options...
SIMPLE_XP Posted August 6, 2007 Share Posted August 6, 2007 You need to add the following to your script... (You can comment out the Msgbox line in the function so that it is silent...) Basically you are adding a custom error function to handle the errors. I added the static Hex error in the function that will trap the specific error of the dll not being registered. Good luck! Opt("RunErrorsFatal", 0) ;SET ERRORS AS SILENT NOT FATAL $OBJECT_ERROR_HANDLER = ObjEvent("AutoIt.Error","PRINTER_ERROR_FUNC") ;CUSTOM ERROR HANDLER FUNCTION Func PRINTER_ERROR_FUNC() $HexNumber=hex($OBJECT_ERROR_HANDLER.number,8) If $HexNumber ="800401F3" Then $DO_NOT_RUN = True MsgBox(0, "Error", "Please register prnadmin.dll before using") Else Msgbox(0,"","Please let me (Jim Parsons) the Author know we intercepted a COM Error !" & @CRLF & _ "Number is: " & $HexNumber & @CRLF & _ "Windescription is: " & $OBJECT_ERROR_HANDLER.windescription ) EndIf SetError(1) Endfunc Hero's Dawn, an RPG Adventure completely coded in AutoITwmifunctions UDF, WMI UDF Link to comment Share on other sites More sharing options...
ejbmail Posted August 6, 2007 Author Share Posted August 6, 2007 Thank Much that worked great.You need to add the following to your script... (You can comment out the Msgbox line in the function so that it is silent...)Basically you are adding a custom error function to handle the errors. I added the static Hex error in the function that will trap the specific error of the dll not being registered.Good luck! Opt("RunErrorsFatal", 0) ;SET ERRORS AS SILENT NOT FATAL $OBJECT_ERROR_HANDLER = ObjEvent("AutoIt.Error","PRINTER_ERROR_FUNC");CUSTOM ERROR HANDLER FUNCTIONFunc PRINTER_ERROR_FUNC() $HexNumber=hex($OBJECT_ERROR_HANDLER.number,8) If $HexNumber ="800401F3" Then $DO_NOT_RUN = True MsgBox(0, "Error", "Please register prnadmin.dll before using") Else Msgbox(0,"","Please let me (Jim Parsons) the Author know we intercepted a COM Error !" & @CRLF & _ "Number is: " & $HexNumber & @CRLF & _ "Windescription is: " & $OBJECT_ERROR_HANDLER.windescription ) EndIf SetError(1) Endfunc 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