Hi guys, I'm an experienced VB programmer, but recently started using C# and I like it. But what I need to do now, is get a list of all printers installed on the computer (not a problem) and print a page to all of them (also not a problem)...

BUT (You knew there was a but coming...) it also tries to print to Virtual Printers (Like Adobe PDF, NoteWriter, XML loader, ect) which pops up a really annoying dialogue each time. I want to eventually use this automatically, IE no human intervention to close pesky dialogues.

So is there some way I can find out if it is a virtual printer?

Heres the relevant portion of my code:

String server = Console.ReadLine();
            if (server.ToLower() == "y")
                server = Environment.UserDomainName;
            else
                server = Environment.MachineName;
            System.Management.ManagementObjectCollection moReturn = default(System.Management.ManagementObjectCollection);
            System.Management.ManagementObjectSearcher moSearch = default(System.Management.ManagementObjectSearcher);
                List<String> Printers = new List<String>();      
            try {
	            moSearch = new System.Management.ManagementObjectSearcher("Select * from Win32_Printer");
                moSearch.Scope.Path.Server = server;
	            moReturn = moSearch.Get();
                Console.WriteLine("Fetching Printer list from " + server + "...");

	            foreach (System.Management.ManagementObject mo in moReturn) {
                    Printers.Add(mo.GetPropertyValue("name").ToString());
		           Console.WriteLine(mo.GetPropertyValue("name"));
	            }
            } catch (Exception ex) {
	            Console.WriteLine(ex.Message);
            } finally {
	            moReturn = null;
	            moSearch = null;
            }
            System.Drawing.Printing.PrintDocument pd = new System.Drawing.Printing.PrintDocument();
            pd.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(pd_PrintPage);
            foreach (String printer in Printers)
            {
                Pos = 0;
                pd.PrinterSettings.PrinterName = printer;
                PB = new Rectangle(0, 0, pd.DefaultPageSettings.Bounds.Width, pd.DefaultPageSettings.Bounds.Height);
                try
                {
                    pd.Print();
                }
                catch
                {
                    continue;
                }
            }

You are going about finding printers in an odd way, just use LocalPrintServer. Other than that, I'm not sure if you can. You don't actually print to a printer anymore, you print to a print queue (which then gets sent to the printer). The print queue takes on some of the attributes of the printer, but looking through them I can't find anything that signifies that it is a 'real' vs 'virtual' printer.

There could be something there (there are a lot of classes you can deal with in that section of .NET) but as I said, I didn't find anything.

Edit: Looking some more, I notice that only my physical printer has PrintQueueAttributes.EnableBidi (bi-directional communication). That may be the key you are looking for :)

EnableBidi Attribute is not always true for all physical printer,it may be fasle for Some Old Models of printers who do not communicate in bidirectional manner.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.