Solved

How to detect Windows virtual printer from physical printer?

Posted on 2011-02-27
3
602 Views
Last Modified: 2014-01-12
I have a Windows application.  How can I detect in code whether the printer is a physical printer or a virtual print (such as Adobe PDF, Mixrosoft XPS, FAX)?? I want to prevent the user from printing to a virtual printer.
0
Comment
Question by:abutler777
3 Comments
 
LVL 41

Accepted Solution

by:
graye earned 500 total points
ID: 34998243
Unforuneately, there's no easy way to do it...   But below is a brute-force approach that I've been using.  This example is just cut-n-pasted from working code, so please disregard things that are not applicable.
'
    ' Get information about installed printers (includes networked printers).
    '
    Public Sub GetPrinters()
        Dim obj As ManagementObject
        Dim cnt As Integer
        Dim temp As String
        Dim dr As SOSOSDataset.PrintersRow

        Try
            cnt = 0
            wmi.Path.RelativePath = "Win32_Printer"
            For Each obj In wmi.GetInstances()
                dr = ds.Printers.NewPrintersRow
                dr.ID_Printer = ID
                dr.Printer_ID = cnt
                dr.Printer = Left(obj("Caption").ToString, ds.Printers.PrinterColumn.MaxLength)
                dr.Printer_Port = Left(obj("PortName").ToString, ds.Printers.Printer_PortColumn.MaxLength)
                ' Is this a *real* local printer?
                temp = Left(dr.Printer_Port, 3)
                If (temp = "LPT" Or temp = "COM" Or temp = "USB" Or temp = "DOT") And dr.Printer.StartsWith("Acrobat") = False And dr.Printer.StartsWith("Adobe") = False And dr.Printer.StartsWith("Generic") = False And dr.Printer.StartsWith("\\") = False Then
                    If Not IsNothing(obj("ShareName")) Then
                        dr.Printer_SharedAs = Left(obj("ShareName").ToString, ds.Printers.Printer_SharedAsColumn.MaxLength)
                    End If
                    ds.SOS(0).Printer = dr.Printer
                End If
                ds.Printers.AddPrintersRow(dr)
                cnt += 1
            Next
        Catch ex As Exception
            dr = ds.Printers.NewPrintersRow
            dr.ID_Printer = ID
            dr.Printer_ID = -1
            dr.Printer = Left("Error: " & ex.Message, ds.Printers.PrinterColumn.MaxLength)
            ds.Printers.AddPrintersRow(dr)

            ' Check to see if this is an error that is fairly common.  If so,
            ' let's not clog up the error log with it.
            If ex.GetType Is GetType(System.Management.ManagementException) Then
                If CType(ex, ManagementException).ErrorCode = ManagementStatus.Failed Then
                    Misc.ErrorLog(ex, MachineName, "Printers", Misc.ErrLogLevel.Full)
                    Exit Try
                End If
            End If
            Misc.ErrorLog(ex, MachineName, "Printers", Misc.ErrLogLevel.Errors)
        End Try
    End Sub

Open in new window

0
 
LVL 38

Expert Comment

by:hdhondt
ID: 39774504
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
When I recently replaced my image transfer kit on my office HP color laserjet 5550dn printer, I had a slight problem.  The left bracket that holds the transfer kit got stuck in the upright locked position instead of being at a 45 degree angle facing…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now