We will now use the VBScript FileSystemObject object and the WSH Network object. The Network object will give us the methods we need to open a printer connection, and the FileSystemObject will allow us to stream our output to the printer. The AddPrinterConnection method maps the remote printer specified by strPrinterPath to the local resource name. In this example, we use LPT1. Connect to Network Printer from Windows Scripting Host ' objWSHNet.
Error trapping is always a good idea.
The following section will trap for errors while closing the connection to our printer object. Close the print device object and trap for errors ' On Error Resume Next objPrinter. If Err Then Response. If we've made it to the following section, the operation has been successful. Output a confirmation ' Response.