tucas.blogg.se

Sample print test page
Sample print test page




sample print test page

Of course, that’s all well and good if you’re running Windows XP. No need to walk all the way to the printer only to find out that, for some reason, the print test failed. What makes this especially nice is : 1) because this is WMI, we can print test pages from remote machines just as easily as we can from the local machine and, 2) the return value will tell us whether or not the print test succeeded. Either way we echo the appropriate message to the screen. If errReturn is 0 that means the test page printed successfully if errReturn is anything but 0 then something went wrong and the test page could not be printed. But, rules are rules, right?Īfter binding to the printer (and our collection will consist of only one printer, because DeviceIDs must be unique) we call the PrintTestPage method, capturing the return value in a variable named errReturn. If you have back-to-back \\’s like we do here, you must preface each slash with a second slash, yielding this crazy-looking construct: \\\\. Just another one of the little eccentricities we’ve come to love about WMI: any time you use a \ in a Where clause you must preface it with a second slash. Consequently we need to use this as the DeviceID: \\\\atl-ps-01\\color-printer Note that because we are using the DeviceID as part of a Where clause ( Where DeviceID =) we need to “escape” each \ in the printer path. Wscript.Echo “The test page could not be printed.”Īll we do in this script is connect to the WMI service, then run a query that binds us to the printer with the DeviceID \\atl-ps-01\color-printer.

sample print test page

Wscript.Echo “The test page was printed successfully.” (“Select * from Win32_Printer Where DeviceID = ‘\\\\atl-ps-01\\color-printer'”) Set colPrinters = objWMIService.ExecQuery _ Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\cimv2”) Here’s a sample script that does just that: strComputer = “.” As you might expect, this means you can bind to a given printer on a computer and then call the PrintTestPage method to, well, print a test page. As long as you’re running Windows XP this is an easy one that’s because the revised Win32_Printer class introduced in Windows XP includes a method called PrintTestPage. Hey, Scripting Guy! How can I print a test page to a printer?






Sample print test page