none
Get copy of files being printed in windows Printer Queue? RRS feed

  • Question

  • How to get copy of files being printed in windows Printer Queue?

    For example, If there is a file in C:\test.pdf and it is being printed , a copy of the file should be created in another path like C:\files\

    Sunday, May 19, 2019 6:46 PM

Answers

All replies

  • Hi,

    You want to determine if the file is being printed, and if so, copy it to another location?

    Imports System.Printing
    
    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            If GetPrintQueue("C:\test.pdf").IsPrinting Then
                System.IO.File.Copy("C:\test.pdf", " C:\files\test.pdf", True)
            End If
    
        End Sub
        Private Function GetPrintQueue(ByVal PrinterName As String) As PrintQueue
            Dim pr As LocalPrintServer = New LocalPrintServer()
            pr.Refresh()
            Dim enumerationFlags As EnumeratedPrintQueueTypes() = {EnumeratedPrintQueueTypes.Local, EnumeratedPrintQueueTypes.Connections}
    
            For Each pq As PrintQueue In pr.GetPrintQueues(enumerationFlags)
    
                If pq.Name = PrinterName Then
                    Return pq
                End If
            Next
    
            Return Nothing
        End Function
    End Class
    

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, May 20, 2019 6:35 AM
  • Hi,

    You want to determine if the file is being printed, and if so, copy it to another location?

    Imports System.Printing
    
    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            If GetPrintQueue("C:\test.pdf").IsPrinting Then
                System.IO.File.Copy("C:\test.pdf", " C:\files\test.pdf", True)
            End If
    
        End Sub
        Private Function GetPrintQueue(ByVal PrinterName As String) As PrintQueue
            Dim pr As LocalPrintServer = New LocalPrintServer()
            pr.Refresh()
            Dim enumerationFlags As EnumeratedPrintQueueTypes() = {EnumeratedPrintQueueTypes.Local, EnumeratedPrintQueueTypes.Connections}
    
            For Each pq As PrintQueue In pr.GetPrintQueues(enumerationFlags)
    
                If pq.Name = PrinterName Then
                    Return pq
                End If
            Next
    
            Return Nothing
        End Function
    End Class

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Yes, but in the line "  If GetPrintQueue("C:\test.pdf").IsPrinting Then ",  the file is specified in C drive.

    I need to check for any file that is in printing queue and being printed . Files might be in different locations

    Monday, May 20, 2019 7:07 AM
  • Hi,

    add a timer,monitor the following function

     Private Function GetPrintname() As String
            Dim pr As LocalPrintServer = New LocalPrintServer()
            Dim printname As String = Nothing
            pr.Refresh()
            Dim enumerationFlags As EnumeratedPrintQueueTypes() = {EnumeratedPrintQueueTypes.Local, EnumeratedPrintQueueTypes.Connections}
    
            For Each pq As PrintQueue In pr.GetPrintQueues(enumerationFlags)
    
                'If pq.Name = PrinterName Then
                '    Return pq
                'End If
                If pq.IsPrinting Then
                    printname = pq.Name
                End If
            Next
    
            Return printname
        End Function

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Monday, May 20, 2019 8:25 AM
  • Hi,

    add a timer,monitor the following function

     Private Function GetPrintname() As String
            Dim pr As LocalPrintServer = New LocalPrintServer()
            Dim printname As String = Nothing
            pr.Refresh()
            Dim enumerationFlags As EnumeratedPrintQueueTypes() = {EnumeratedPrintQueueTypes.Local, EnumeratedPrintQueueTypes.Connections}
    
            For Each pq As PrintQueue In pr.GetPrintQueues(enumerationFlags)
    
                'If pq.Name = PrinterName Then
                '    Return pq
                'End If
                If pq.IsPrinting Then
                    printname = pq.Name
                End If
            Next
    
            Return printname
        End Function

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    I did what you said. This function gets printer's name. Not the file path that is being printed.

    beside that , there is the same problem with "  System.IO.File.Copy("C:\test.pdf", " C:\files\test.pdf", True)"

    Again files path are specified.

    The scenario is that we do not know where the printing document is. but it is in queue list and then  being printed. So we need to get it's path and copy the file into another path


    • Edited by Kevin993 Tuesday, May 21, 2019 6:01 AM
    Monday, May 20, 2019 12:41 PM
  • Hi,

    You want to determine if the file is being printed, and if so, copy it to another location?

    Imports System.Printing
    
    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            If GetPrintQueue("C:\test.pdf").IsPrinting Then
                System.IO.File.Copy("C:\test.pdf", " C:\files\test.pdf", True)
            End If
    
        End Sub
        Private Function GetPrintQueue(ByVal PrinterName As String) As PrintQueue
            Dim pr As LocalPrintServer = New LocalPrintServer()
            pr.Refresh()
            Dim enumerationFlags As EnumeratedPrintQueueTypes() = {EnumeratedPrintQueueTypes.Local, EnumeratedPrintQueueTypes.Connections}
    
            For Each pq As PrintQueue In pr.GetPrintQueues(enumerationFlags)
    
                If pq.Name = PrinterName Then
                    Return pq
                End If
            Next
    
            Return Nothing
        End Function
    End Class

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    I want exactly the inverse of :

      If GetPrintQueue("C:\test.pdf").IsPrinting Then
                System.IO.File.Copy("C:\test.pdf", " C:\files\test.pdf", True)
            End If

    In your code , we know where the file is located (C:\ ...) and we want to know if it is in queue and being printed or not.

    In the desired code , we don't know location of the file, but we know it is in queue and being printed




    • Edited by Kevin993 Tuesday, May 21, 2019 6:05 AM
    Tuesday, May 21, 2019 6:04 AM
  • Hi,

    It seems impossible to achieve,see the following link

    https://social.msdn.microsoft.com/Forums/en-US/cdf2e71e-3a10-4347-89b9-2d7d8184a858/how-to-find-file-location-which-has-been-queued-for-printing?forum=csharpgeneral

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Kevin993 Tuesday, May 21, 2019 7:18 AM
    Tuesday, May 21, 2019 6:45 AM
  • Hi,

    It seems impossible to achieve,see the following link

    https://social.msdn.microsoft.com/Forums/en-US/cdf2e71e-3a10-4347-89b9-2d7d8184a858/how-to-find-file-location-which-has-been-queued-for-printing?forum=csharpgeneral

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    According to the link, I guess so. But there is an interesting point :

    Imagine there is a pdf file named "File1.pdf". I copy the file into each available drive (for example 4 drives) and I put the file in printing queue from each drive. Now my printing queue has 4 jobs , all the documents' name is identical but in different locations. (in this case there wouldn't be any problem because content of pdf file is the same, but what if different files have identical names in different locations?)

    The only way I can think of to skin this cat (If I were windows) is to load each file into memory and clean up after finishing the job. So , no location required!

    Tuesday, May 21, 2019 7:17 AM