Forum Discussion

Charelle's avatar
Charelle
New Contributor
14 years ago

How to get Printer job information

Hi,

 I want test if the job I printed with my application is sent in the queue of my local printer. I want to know the document name and how many page is that document.



I found that I could probably use WMI or Win32API to get that information.



I found some vbscript samples to access to printers with WMI. I translated in jscript:



var
strComputer = "."

var objWMIService = GetObject("winmgmts:" + "{impersonationLevel=impersonate}!\\" + strComputer + "\root\cimv2");


objWMIService = GetObject("winmgmts:" + "{impersonationLevel=impersonate}!\\" + strComputer + "\root\cimv2");

var colInstalledPrinters = objWMIService.ExecQuery("Select * from Win32_Printer");




colInstalledPrinters = objWMIService.ExecQuery("Select * from Win32_Printer");But the GetObject gave me that error:

OLE error 80041021






Then I tried to replace the GetObject by the testComplete extension object : WMI.Service



I think it works(It doesn't give error), but now I would like to know how to iterate in jscript through colInstalledPrinters[Object] to get the information I need.



Do you have some code sample with WMI or Win32API?

Or do you see a better way to test printing jobs?





Best regards,



Charelle


2 Replies

  • Charelle's avatar
    Charelle
    New Contributor
    Sorry there was some issue whe I posted my first message and some code was duplicated. Here are the two samples:





    //First try:

    var strComputer = "."

    var objWMIService = GetObject("winmgmts:" + "{impersonationLevel=impersonate}!\\" + strComputer + "\root\cimv2");

    var colInstalledPrinters =  objWMIService.ExecQuery("Select * from Win32_Printer");


    Error msg:


    ---------------------------

    TestComplete

    ---------------------------

    An exception occurred in the "Printer" unit at line 5:

    OLE error 80041021


    ---------------------------

    OK  

    ---------------------------




    //Second try:

    var strComputer = "."

    var objWMIService = WMI.Service;

    var colInstalledPrinters =  objWMIService.ExecQuery("Select * from Win32_Printer");


    now how tu use: colInstalledPrinters

  • Charelle's avatar
    Charelle
    New Contributor
    Hello,

       I didn't found how to use WMI Service with TestComplete, but I've found how to create a batch file that gives me the information that I need.



    The command line used calls cscript.vbs :



    C:\WINDOWS\system32\cscript.exe c:\WINDOWS\system32\prnjobs.vbs -x -p TestsAuto -l  > printed.txt



    Now I can parse the file printed.txt to get printed jobs information.



    Does someone have someting better to propose?



    If someone have ever use WMI Service with TestComplete, I'm still interest to learn how to use it.



    Thank you



    Charelle