[点晴永久免费OA]C#获取打印机工作状态,是否离线,打印机名称,端口号等打印机属性信息
当前位置:点晴教程→点晴OA办公管理信息系统
→『 经验分享&问题答疑 』
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Management;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class FrmGetPrinterStatus : Form
{
public FrmGetPrinterStatus()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string query = string.Format("select * from Win32_Printer ");
var searcher = new ManagementObjectSearcher(query);
var printers = searcher.Get();
foreach (var printer in printers)
{
//显示部分属性
Console.WriteLine(printer.Properties["Name"].Value); //获取打印机名称
Console.WriteLine(printer.Properties["PortName"].Value); //获取打印机端口号
Console.WriteLine(printer.Properties["Default"].Value); //获取打印机是否是默认打印机
Console.WriteLine(printer.Properties["PrinterStatus"].Value); //获取打印机工作状态
Console.WriteLine(printer.Properties["WorkOffline"].Value); //获取打印机是否离线
//显示所有属性到即时窗口
foreach (var property in printer.Properties)
{
Console.WriteLine(string.Format("\t{0}: {1}", property.Name, property.Value));
}
Console.WriteLine();
}
}
}
}
该文章在 2022/7/20 11:10:20 编辑过 |
关键字查询
相关文章
正在查询... |