【问题标题】:How to find the printer type in c#?如何在 C# 中找到打印机类型?
【发布时间】:2016-07-17 08:48:55
【问题描述】:

如何找到我们PC中安装的打印机类型,无论是c#中的点阵、激光还是喷墨?

【问题讨论】:

  • 对不起,我怎么能找到安装的打印机是dotmatrix还是不是..
  • 我的要求是我有 12 台不同公司的打印机。 3 dotmatrix ,4 Laser and rest 5 inkject 我需要将它打印到 dotmatrix ,没有给出我们需要识别打印机是 dotmatrix 的打印机名称?
  • 使用 WMI Win32_Printer 并阅读这部分“MarkingTechnology”:msdn.microsoft.com/en-us/library/aa394363(v=vs.85).aspx

标签: c# .net c#-4.0 c#-3.0


【解决方案1】:

以下类为您提供打印机是点阵式、激光式还是喷墨式:

using System;
using System.Management;

namespace ConsoleDemo
{
class Printer
{
 public enum TechnologyType
    {
        Other = 1,
        Unknown = 2,
        Electrophotographic_LED = 3,
        Electrophotographic_Laser = 4,
        Electrophotographic_Other = 5,
        Impact_Moving_Head_Dot_Matrix_9pin = 6,
        Impact_Moving_Head_Dot_Matrix_24pin = 7,
        Impact_Moving_Head_Dot_Matrix_Other = 8,
        Impact_Moving_Head_Fully_Formed = 9,
        Impact_Band = 10,
        Impact_Other = 11,
        Inkjet_Aqueous = 12,
        Inkjet_Solid = 13,
        Inkjet_Other = 14,
        Pen_ = 15,
        Thermal_Transfer = 16,
        Thermal_Sensitive = 17,
        Thermal_Diffusion = 18,
        Thermal_Other = 19,
        Electroerosion = 20,
        Electrostatic = 21,
        Photographic_Microfiche = 22,
        Photographic_Imagesetter = 23,
        Photographic_Other = 24,
        Ion_Deposition = 25,
        eBeam = 26,
        Typesetter = 27
    }
    
    public static void GetPrinterInfo()
    {
        var printerQuery = new ManagementObjectSearcher("SELECT * from Win32_Printer");
        foreach (var printer in printerQuery.Get())
        {
            var name = printer.GetPropertyValue("Name");
            var status = printer.GetPropertyValue("Status");
            var isDefault = printer.GetPropertyValue("Description");
            var MarkingTechnology = printer.GetPropertyValue("MarkingTechnology");
           var CurrentCapabilities = (string )printer.GetPropertyValue("CurrentCapabilities");
            Console.WriteLine("Name:{0} |(Status: {1} | Description: {2}| Technology: {3} | {4} ",
                name, status, isDefault, MarkingTechnology , CurrentCapabilities);
        }
    }

}

}

枚举 TechnologyType 为您提供打印机技术的类型。

更多信息回顾:Win32_Printer class

【讨论】:

  • var MarkingTechnology = printer.GetPropertyValue("MarkingTechnology"); var CurrentCapabilities = (string)printer.GetPropertyValue("CurrentCapabilities");这两个总是显示 null
  • 可能是打印机安装的设备驱动不支持返回这些信息。您可以检查 CurrentLanguage 吗?您可以找到像 Epson (11) 之类的值
猜你喜欢
  • 2018-05-13
  • 2023-03-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多