Results 1 to 9 of 9

Thread: [RESOLVED] How to set offline or pause Printer

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2013
    Posts
    17

    Resolved [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.

  2. #2
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,024

    Re: How to set offline or pause Printer

    Are you trying to interact with the printer? Or is this related to reporting?
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Oct 2013
    Posts
    17

    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

  4. #4
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,024

    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?
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  5. #5
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    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

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Oct 2013
    Posts
    17

    Re: How to set offline or pause Printer

    i have a administrator rights as a user

  7. #7
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,024

    Re: How to set offline or pause Printer

    Then follow the link provided by Merrion as reference..
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  8. #8
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    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

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Oct 2013
    Posts
    17

    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
  •  



Click Here to Expand Forum to Full Width