Solved

How to detect Windows virtual printer from physical printer?

Posted on 2011-02-27
3
588 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:Herman D'Hondt
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

760 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

19 Experts available now in Live!

Get 1:1 Help Now