Jump to content
Sign in to follow this  
emendelson

Test whether default printer can print?

Recommended Posts

This is a question about a script that will run on Windows 2000, XP, and above (I hope) only. I want to be able to test whether the Windows default printer is actually working or not by printing a test page (even a single word is enough) so that the user can see if the printer is actually functioning.

I know how to use RegRead to determine the current default printer (in fact, this is already in my script). As far as I can tell, the print dialog in Notepad always selects shows the default printer (other applications may show the most-recently used printer instead). But it seems to me more reliable to be able to access the driver for the default printer and use the "print test page" feature instead.

Does anyone know a way to script the "print test page" item for the default printer??

Thanks for any help.

Share this post


Link to post
Share on other sites

Try:

$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate,(LoadDriver)}!\\" & @ComputerName & "\root\cimv2")
$colInstalledPrinters =  $objWMIService.ExecQuery ("Select * from Win32_Printer Where Default = True")
For $objPrinter in $colInstalledPrinters
    $uResult = $objPrinter.PrintTestPage()  
Next

Share this post


Link to post
Share on other sites

Try:

$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate,(LoadDriver)}!\\" & @ComputerName & "\root\cimv2")
$colInstalledPrinters =  $objWMIService.ExecQuery ("Select * from Win32_Printer Where Default = True")
For $objPrinter in $colInstalledPrinters
    $uResult = $objPrinter.PrintTestPage()  
Next
Absolutely one-hundred-percent perfect. Also elegant.

Thank you!

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...