|
-
Dec 4th, 2013, 02:52 AM
#1
Thread Starter
Junior Member
[RESOLVED] How to set offline or pause Printer
hy! i am using vb.net And i am trying to offline or pause print. how it is possible i need a help
Last edited by ccc4dev; Dec 6th, 2013 at 12:18 AM.
-
Dec 4th, 2013, 03:27 AM
#2
Re: How to set offline or pause Printer
Are you trying to interact with the printer? Or is this related to reporting?
-
Dec 4th, 2013, 04:03 AM
#3
Thread Starter
Junior Member
Re: How to set offline or pause Printer
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
-
Dec 4th, 2013, 04:33 AM
#4
Re: How to set offline or pause Printer
Based from the documentation:
Every user is allowed to get the printer status but only users with sufficient access rights may change the printer settings.
What rights do you have as a user?
-
Dec 4th, 2013, 05:05 AM
#5
Re: How to set offline or pause Printer
You (or the account running code that is doing this operation) need to have admin rights to change the printer settings.
Try
Code:
Dim lret As Long
Dim pDef As PRINTER_DEFAULTS
pdef.DesiredAccess = PRINTER_ALL_ACCESS
lret = OpenPrinter(Printer.DeviceName, mhPrinter, pDef)
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 CodePlex
-
Dec 4th, 2013, 05:16 AM
#6
Thread Starter
Junior Member
Re: How to set offline or pause Printer
i have a administrator rights as a user
-
Dec 4th, 2013, 06:06 AM
#7
Re: How to set offline or pause Printer
Then follow the link provided by Merrion as reference..
-
Dec 4th, 2013, 06:24 AM
#8
Re: How to set offline or pause Printer
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
-
Dec 5th, 2013, 11:49 PM
#9
Thread Starter
Junior Member
Re: How to set offline or pause Printer
thanks to all friends this code work for me
Dim pi As New PrinterInformation("Printer Name",SpoolerApiConstantEnumerations.PrinterAccessRights.PRINTER_ALL_ACCESS, False)
pi.PausePrinting
Last edited by ccc4dev; Dec 6th, 2013 at 12:16 AM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|