Solved

How to detect Windows virtual printer from physical printer?

Posted on 2011-02-27
3
616 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
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…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
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…

838 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