如何用C#判断打印机工作状态
展开全部
如何用C#判断打印机工作状态
方法一:
using System.DirectoryServices;
using ActiveDs;(Com 组键里的 Active DS Type Library 目录Windos\system32\activeds.tlb)
//Printer status flags - see SDK docs for status values (IADsPrintQueueOperations) 打印机状态
[Flags]
private enum PrinterStatus
{
Paused = 1,
DeletePending = 2,
Error = 3,
PaperJam = 4,
PaperOut = 5
}
private void GetPrinterStatus1()
{
try
{
this.Cursor = Cursors.WaitCursor;
DirectoryEntry lPrinter = new DirectoryEntry("WinNT://192.168.1.77/Adobe PDF", null, null, AuthenticationTypes.ServerBind);
//Printer path
txtState.Text += Environment.NewLine + "Printer path:" + lPrinter.Path;
System.DirectoryServices.PropertyCollection lPropertyColl = lPrinter.Properties;
foreach (string pcName in lPropertyColl.PropertyNames)
{
txtState.Text += Environment.NewLine + pcName + ":\t" + (lPropertyColl[pcName])[0].ToString();
}
txtState.Text += Environment.NewLine + "---------------------------------";
// Use the PrintqueueOperations interface to contol the printer Queue
IADsPrintQueueOperations lPrintQueue = lPrinter.NativeObject as IADsPrintQueueOperations;
if (lPrintQueue != null)
{
if (lPrintQueue.Status == (int)PrinterStatus.Paused) // If paused resume else pause printer
{
lPrintQueue.Resume();
}
else
{
lPrintQueue.Pause();
}
// Use the IADsPrintJob to control individual printjobs
foreach (IADsPrintJob pJob in lPrintQueue.PrintJobs())
{
txtState.Text += Environment.NewLine + pJob.Description + pJob.Name;
IADsPrintJobOperations pjo = pJob as IADsPrintJobOperations;
txtState.Text += Environment.NewLine + pjo.Name;
// Use IADsPrintJob.Name as arg. to remove the job from the queue
//删除打印列表里的庸余打印任务
//lPrintQueue.PrintJobs().Remove(pJob.Name);
}
}
lPrinter.Dispose();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
this.Cursor = Cursors.Default;
}
}
方法一:
using System.DirectoryServices;
using ActiveDs;(Com 组键里的 Active DS Type Library 目录Windos\system32\activeds.tlb)
//Printer status flags - see SDK docs for status values (IADsPrintQueueOperations) 打印机状态
[Flags]
private enum PrinterStatus
{
Paused = 1,
DeletePending = 2,
Error = 3,
PaperJam = 4,
PaperOut = 5
}
private void GetPrinterStatus1()
{
try
{
this.Cursor = Cursors.WaitCursor;
DirectoryEntry lPrinter = new DirectoryEntry("WinNT://192.168.1.77/Adobe PDF", null, null, AuthenticationTypes.ServerBind);
//Printer path
txtState.Text += Environment.NewLine + "Printer path:" + lPrinter.Path;
System.DirectoryServices.PropertyCollection lPropertyColl = lPrinter.Properties;
foreach (string pcName in lPropertyColl.PropertyNames)
{
txtState.Text += Environment.NewLine + pcName + ":\t" + (lPropertyColl[pcName])[0].ToString();
}
txtState.Text += Environment.NewLine + "---------------------------------";
// Use the PrintqueueOperations interface to contol the printer Queue
IADsPrintQueueOperations lPrintQueue = lPrinter.NativeObject as IADsPrintQueueOperations;
if (lPrintQueue != null)
{
if (lPrintQueue.Status == (int)PrinterStatus.Paused) // If paused resume else pause printer
{
lPrintQueue.Resume();
}
else
{
lPrintQueue.Pause();
}
// Use the IADsPrintJob to control individual printjobs
foreach (IADsPrintJob pJob in lPrintQueue.PrintJobs())
{
txtState.Text += Environment.NewLine + pJob.Description + pJob.Name;
IADsPrintJobOperations pjo = pJob as IADsPrintJobOperations;
txtState.Text += Environment.NewLine + pjo.Name;
// Use IADsPrintJob.Name as arg. to remove the job from the queue
//删除打印列表里的庸余打印任务
//lPrintQueue.PrintJobs().Remove(pJob.Name);
}
}
lPrinter.Dispose();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
this.Cursor = Cursors.Default;
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
北京合创芯彩科技
2024-08-22 广告
2024-08-22 广告
请问打印控制系统哪家好?建议咨询北京合创芯彩科技有限公司,北京合创芯彩科技有限公司(英文名:ICCOLOR),专注于打印技术及相关产品的开发,公司拥有多项自主创新的技术成果,拥有多项软件著作权和专利,是国内独家能提供从主控芯片、到办公设备开...
点击进入详情页
本回答由北京合创芯彩科技提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询