hi masters...
i want to get jobs in printer queue...
i didn't have idea to do this. please help me.
any help will be appreciated.
thanks before.

Recommended Answers

All 6 Replies

try this following code :

Private Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, pDefault As Any) As Long
Private Declare Function ClosePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long
Private Declare Function EnumJobs Lib "winspool.drv" Alias "EnumJobsA" (ByVal hPrinter As Long, ByVal FirstJob As Long, ByVal NoJobs As Long, ByVal Level As Long, pJob As Any, ByVal cdBuf As Long, pcbNeeded As Long, pcReturned As Long) As Long
Private Sub Form_Load()
   
    Dim hPrinter As Long, lNeeded As Long, lReturned As Long
    Dim lJobCount As Long
    OpenPrinter Printer.DeviceName, hPrinter, ByVal 0&
    EnumJobs hPrinter, 0, 99, 1, ByVal 0&, 0, lNeeded, lReturned
    If lNeeded > 0 Then
        ReDim byteJobsBuffer(lNeeded - 1) As Byte
        EnumJobs hPrinter, 0, 99, 1, byteJobsBuffer(0), lNeeded, lNeeded, lReturned
        If lReturned > 0 Then
            lJobCount = lReturned
        Else
            lJobCount = 0
        End If
    Else
        lJobCount = 0
    End If
    ClosePrinter hPrinter
    MsgBox "Jobs in printer queue: " + CStr(lJobCount), vbInformation
End Sub
commented: great code and always helping... +1
commented: wow +1
commented: :confused: +1
commented: yombex +1
commented: :twisted: +1

don't forget to give a feedback :)

commented: Great Feedback for your code friend.... +1
commented: thx +1

oh.. thank you very much jx_man...
it working like a charm.

yeah..You're welcome friend :)

Hopefully JX_Man is still around - I'm using your posted code...I'm not a VB expert, so I'm trying to figure out where to specify the printer...can I just add this line after the Dims and before the open?

pPrinterName = "\\DHCP-printserver\HPLaserJet5N"

Is this the proper way to do it? I've got it working for one print queue, but not another, and I'm wondering if I'm doing this correctly...

Any information appreciated.

Actually, I've come to find this doesn't work on any of my server OS's, but works fine on Windows XP...

Any ideas?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.