Accessing Print Queue From ASP.NET

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Operating System: Windows 2003 Server R2
..NET Framework Version: 1.1
Web Server: IIS Server 6.0
Programming Language: VB.NET

I have been trying to find out a way to access the print queue using
ASP.NET. I want to be able to access the print queue for a particular
network printer and display each job and quantity in the Web browser.
I am importing the System.Runtime.InteropServices Namespace and this
is why I am posting this message here.

I know that by using DllImport, I can reference the winspool.drv
driver and access some Win32 API functions, but I have no idea if it
is even possible to access the print queue of a particular network
printer. I tested the following two functions on a local printer,
Adobe PDF. This is a virtual printer that gets installed when you
install Adobe Acrobat. it functions the same as any other physical
printer, but it just prints out to a PDF file instead.

The Default.aspx.vb code-behind file contains these two functions:

<DllImport("winspool.drv", EntryPoint:="OpenPrinterA", _
SetLastError:=True, CharSet:=CharSet.Ansi, _
ExactSpelling:=True, _
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function OpenPrinter(ByVal pPrinterName As String,
_
ByRef phPrinter As Int32, _
ByVal pDefault As Int32 _
) As Boolean

End Function

<DllImport("winspool.drv", EntryPoint:="ClosePrinter", _
SetLastError:=True, _
ExactSpelling:=True, _
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function ClosePrinter(ByVal hPrinter As Int32) As
Boolean

End Function

The Page_Load function of the Default.aspx.vb file looks like this:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim bResult As Boolean = False
Dim hPrinter As Integer
Dim pDefault As Integer
bResult = OpenPrinter("Adobe PDF", hPrinter, pDefault)
lblOpen.Text = bResult.ToString()
bResult = ClosePrinter(hPrinter)
lblClose.Text = bResult.ToString()
End Sub

As you can see, the Boolean result of the OpenPrinter and ClosePrinter
function calls are displayed in labels on the Web page. Both show
"true" when I run this page in the Web browser. I don't know if this
means anything. Now I'm trying to get to the point where I print
something to the Adobe PDF printer and access the print queue while
the PDF is still being created. Does anyone know how to do this? This
is the same thing as printing out something to a local physical
printer and grabbing the print queue information as it is printing. I
want to grab the name of the print job and the quantity of pages to be
printed. Then I want to be able to do this for multiple print jobs.
Lastly, I want to be able to do this with a network printer.

I know that this sounds kind of complicated, but I would appreciate it
if someone could point me in the right direction. If I need to
elaborate, then please let me know. Thank you in advance.

.



Relevant Pages

  • Re: Control printer from browser
    ... And talking of copies, as others have pointed out, since the printing ... Or open up a firewall port to internet print from the server direct to the printer. ... If the printer runs e.g. standard net print protocols, simply set up a print queue on the server to print to that printer. ... Its entirely possible that if - say - the cashiers machine is Linux that you can, if that machine is on a fixed IP address, connect a printer to it, and 'share' it via some standard method and 'tell' the server to print to it. ...
    (comp.lang.php)
  • Re: How to add an offline printer object in Active Directory
    ... created on a server. ... How about a direct printer when no print queue will be ... a laserjet printer with a network port and users will be printing ... printers to be active before it can be publish in Active Directory. ...
    (microsoft.public.windows.server.active_directory)
  • Re: ISA 2006 and WSUS
    ... ISA, sorry to ask, but where is this located - Event Logs or elsewhere? ... We were previously running ISA Server 2000 on a completely different ... Does the *printer* go offline or the print queue on the print server? ...
    (microsoft.public.isa.configuration)
  • Re: CUPS broadcasting print queue availability
    ... Your printers.conf on the server machine should have a line "Shared Yes". ... My server has a print queue that looks like this: ... BrowseOrder allow,deny ... On the client OS's you should see incoming packets of about 189 bytes ...
    (Debian-User)
  • Re: HP 4MP printer driver current?
    ... I can print the RTF file from the G4, ... When you print to a PDF, ... When Preview is involved in the print process, the original format of ... Preview to examine a document in a print queue. ...
    (comp.sys.mac.system)