Solved

How to detect Windows virtual printer from physical printer?

Posted on 2011-02-27
3
630 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

691 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