using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Management;//在“解决方案资源管理器”中也需添加该引用
namespace PrinterStatus
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnGetStatus_Click(object sender, EventArgs e) //获取打印机状态
{
string printerName = "hp LaserJet 3015 PCL 5";
MessageBox.Show(GetPrinterStat(printerName).ToString());
}
enum PrinterStatus
{
其他状态 = 1, //比如 暂停状态
未知,
空闲, //就绪状态
正在打印,
预热,
停止打印,
打印中,
离线 //脱机 状态
}
private PrinterStatus GetPrinterStat(string PrinterDevice)
{
PrinterStatus ret = 0;
string path = @"win32_printer.DeviceId='" + PrinterDevice + "'";
ManagementObject printer = new ManagementObject(path);
printer.Get();
if ((bool)printer.Properties["WorkOffline"].Value)
{
return PrinterStatus.离线;
}
else
{
ret = (PrinterStatus)Convert.ToInt32(printer.Properties["PrinterStatus"].Value);
}
return ret;
}
}
}
判断打印机状态
最新推荐文章于 2025-05-21 13:42:09 发布