hy! i am using vb.net And i am trying to offline or pause print. how it is possible i need a help
Printable View
hy! i am using vb.net And i am trying to offline or pause print. how it is possible i need a help
Are you trying to interact with the printer? Or is this related to reporting?
i simply want to offline or pause default print.i am trying this link http://www.merrioncomputing.com/Prog...SetPrinter.htm but he is not work for me
Based from the documentation:
What rights do you have as a user?Quote:
Every user is allowed to get the printer status but only users with sufficient access rights may change the printer settings.
You (or the account running code that is doing this operation) need to have admin rights to change the printer settings.
Try
Note that the code you are linking to above is for VB6. You would use the same API calls in VB.NET but they are declared slightly differently ... for a VB.Net version get the code from PrintQueueWatch on CodePlexCode:Dim lret As Long
Dim pDef As PRINTER_DEFAULTS
pdef.DesiredAccess = PRINTER_ALL_ACCESS
lret = OpenPrinter(Printer.DeviceName, mhPrinter, pDef)
i have a administrator rights as a user
Then follow the link provided by Merrion as reference.. :)
From SpoolerApi.vb you need GetPrinter and SetPrinter API declarations.
From SpoolerApiConstantEnumerations.vb you need PrinterAccessRights and PrinterControlCommands
Then your pause and resume code would look like:-
Code:#Region "Paused"
''' -----------------------------------------------------------------------------
''' <summary>
''' True if the printer is paused
''' </summary>
''' <value></value>
''' <remarks>
''' The status is updated when a job is sent to the printer so may not match the true state of the printer
''' if there are no jobs in the queue
''' </remarks>
''' <history>
''' [Duncan] 20/11/2005 Created
''' </history>
''' -----------------------------------------------------------------------------
<Diagnostics.MonitoringDescription("True if the printer is paused")> _
Public Overridable ReadOnly Property Paused() As Boolean
Get
RefreshPrinterInformation(PrinterInfoLevels.PrinterInfoLevel2)
Return ((mPrinter_Info_2.Status And PrinterStatuses.PRINTER_STATUS_PAUSED) = PrinterStatuses.PRINTER_STATUS_PAUSED)
End Get
End Property
#End Region
''' -----------------------------------------------------------------------------
''' <summary>
''' Pauses the printer
''' </summary>
''' <remarks>
''' </remarks>
''' <example>Pauses the named printer
''' <code>
''' Dim pi As New PrinterInformation("Microsoft Office Document Image Writer", SpoolerApiConstantEnumerations.PrinterAccessRights.PRINTER_ALL_ACCESS, False)
''' pi.PausePrinting
''' </code>
''' </example>
''' <history>
''' [Duncan] 20/11/2005 Created
''' </history>
''' -----------------------------------------------------------------------------
Public Sub PausePrinting()
'\\ Do not attempt to pause and already paused printer
If Not Paused Then
Try
If Not SetPrinter(mhPrinter, 0, IntPtr.Zero, PrinterControlCommands.PRINTER_CONTROL_PAUSE) Then
Throw New Win32Exception()
End If
Catch e As Win32Exception
If e.NativeErrorCode = SpoolerWin32ErrorCodes.ERROR_ACCESS_DENIED Then
Throw New InsufficentPrinterAccessRightsException(My.Resources.pem_NoPause, e)
Else
Throw
End If
End Try
End If
End Sub
''' -----------------------------------------------------------------------------
''' <summary>
''' Restart a printer that has been paused
''' </summary>
''' <remarks>
''' </remarks>
''' <example>Resumes printing on the named printing
''' <code>
''' Dim pi As New PrinterInformation("Microsoft Office Document Image Writer", SpoolerApiConstantEnumerations.PrinterAccessRights.PRINTER_ALL_ACCESS, True)
''' pi.ResumePrinting
''' </code>
''' </example>
''' <history>
''' [Duncan] 20/11/2005 Created
''' </history>
''' -----------------------------------------------------------------------------
Public Sub ResumePrinting()
'\\ Do not attempt to resume if the printer is not paused
If Paused Then
Try
If Not SetPrinter(mhPrinter, 0, IntPtr.Zero, PrinterControlCommands.PRINTER_CONTROL_RESUME) Then
Throw New Win32Exception()
End If
Catch e As Win32Exception
If e.NativeErrorCode = SpoolerWin32ErrorCodes.ERROR_ACCESS_DENIED Then
Throw New InsufficentPrinterAccessRightsException(My.Resources.pem_NoResume, e)
Else
Throw
End If
End Try
End If
End Sub
#End Region
thanks to all friends this code work for me
Dim pi As New PrinterInformation("Printer Name",SpoolerApiConstantEnumerations.PrinterAccessRights.PRINTER_ALL_ACCESS, False)
pi.PausePrinting