zoukankan      html  css  js  c++  java
  • C#遍历系统所安装的打印机,使用WMI方式获取打印机的所有属性

    C#里面,虽然在 System.Drawing.Printing 这个namespace下,提供了一些对系统打印机的访问功能,但是,说实话是太弱了,对获取打印机的相关属性基本是无能为力的。

    C#里面获取打印机的详细信息,常用的用2种方式:

    1. 使用 Windows API
    2. 使用 WMI

    我这里使用的是WMI的方式,因为此方式,是采用了类SQL的方法,将windows的WMI管理信息,作为一种数据库的形态来提供的,使用起来比较顺手

    .NET 里面对WMI的使用,是放在 System.Management 这个空间下的,要使用的话,需要先添加对 System.Management.dll 引用

    具体代码如下:

    string wmiSQL = "SELECT * FROM Win32_Printer";
    ManagementObjectCollection printers = new ManagementObjectSearcher(wmiSQL).Get();
    
    foreach (ManagementObject printer in printers)
    {
        PropertyDataCollection.PropertyDataEnumerator pde = printer.Properties.GetEnumerator();
    
        while (pde.MoveNext())
        {
            MessageBox.Show(pde.Current.Name + " : " + pde.Current.Value);
            //显示的是 属性名 : 属性值 的形式
        }
    }

    应该是一目了然了吧,嘿嘿

  • 相关阅读:
    刘汝佳,竖式问题
    二叉树
    sort
    hash
    贪心算法
    FFT,NTT 专题
    hdu 5861 Road 两棵线段树
    hdu 5862 Counting Intersections
    hdu 5833 Zhu and 772002 ccpc网络赛 高斯消元法
    hdu 5800 To My Girlfriend + dp
  • 原文地址:https://www.cnblogs.com/mimi001/p/1671482.html
Copyright © 2011-2022 走看看