2
votes

I am developing an application in .Net(csharp 4.0) which detects if zebra printer is installed and then send a barcode to printer in zpl if zpl is suppported otherwise in EPL. How can I check If zebra printer is installed or is available on network(shared printer) and if so, it supports zpl or epl. I thought to check Device Id. but it looks device id is just display name and is changed when I change the printer name from printers and devices.

thanx

1
Auto-discovery just isn't going to work well. What if two printers are available? This should be config with the printer name or by letting the user pick the printer with PrintDialog.Hans Passant

1 Answers

3
votes

You don't want to check on model-name. Instead, you check which drivers are controlling printers. After all-- A ZPL capable printer is going to be using a Zebra printer driver. And you can check the drivername property as demonstrated below. There are, of course, many more properties available about the printer in question.

using System;
using System.Management;

namespace Test
{
    class Program
    {
        public static void Main(string[] args)
        {
            string query = string.Format("SELECT * from Win32_Printer");
            ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
            ManagementObjectCollection coll = searcher.Get();

            foreach (ManagementObject printer in coll)
            {
                //foreach (PropertyData property in printer.Properties)
                //{
                //    Console.WriteLine(string.Format("{0}: {1}", property.Name, property.Value));
                //}

                var property = printer.Properties["DriverName"];
                if (property.Value.ToString().ToLowerInvariant().Contains("zebra"))
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Write("ZEBRA: ");
                }
                else 
                {
                    Console.ForegroundColor = ConsoleColor.Gray;
                    Console.Write("Regular: ");
                }

                Console.WriteLine(string.Format("{0}: {1}", property.Name, property.Value));
            }

            Console.Write("Press any key to continue . . . ");
            Console.ReadKey(true);
        }
    }
}