入门 硬件知识 电脑基础 上网入门 故障 电脑修护 电脑健康 精通电脑 网站 DIV+CSS 建站知识 SEO知识
教程 电脑操作 平面设计 路由设置 技巧 Word Excel QQ技巧 壁纸 自然风景 酷车美女 系统桌面
系统 安装系统 系统技巧 系统设置 安全 木马查杀 黑客防御 安全资讯 美女 明星写真 清纯美女 性感美女

主页 > 电脑编程 > INTRODUCE

如何用C#判断打印机工作状态

发布时间:2013-04-07 作者:电脑知识网 来源:www.sogoupc.com 字号:

如何用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;
             }
         }
 


文章: 如何用C#判断打印机工作状态
地址:http://www.sogoupc.com/pcbc/201304/1939.html
------分隔线----------------------------
------分隔线----------------------------
栏目分类
热门电脑编程文章推荐