请教如何在C#中c 判断打印机是否缺纸连接

温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
& & {& & & & public static bool CheckPrinter(string printerName1)& & & & {& & & & & & ManagementScope scope = new ManagementScope(@"\root\cimv2");& & & & & & scope.Connect();& & & & & & // Select Printers from WMI Object Collections& & & & & & ManagementObjectSearcher searcher = new& & & & & & &ManagementObjectSearcher("SELECT * FROM Win32_Printer");& & & & & & string printerName = "";& & & & & & foreach (ManagementObject printer in searcher.Get())& & & & & & {& & & & & & & & printerName = printer["Name"].ToString().ToLower();& & & & & & & & if (printerName.IndexOf(printerName1.ToLower()) & -1)& & & & & & & & {& & & & & & & & & && & & & & & & & & & if (printer["WorkOffline"].ToString().ToLower().Equals("true"))& & & & & & & & & & {& & & & & & & & & & & && & & & & & & & & & & & // printer is offline by user& & & & & & & & & & & && & & & & & & & & & }& & & & & & & & & & else& & & & & & & & & & {& & & & & & & & & & & & // printer is not offline& & & & & & & & & & & && & & & & & & & & & & && & & & & & & & & & }& & & & & & & & }& & & & & & }& & & & & && & & & }& & }
阅读(1441)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
loftPermalink:'',
id:'fks_',
blogTitle:'C#判断打印机是否可用。。。',
blogAbstract:'以后留用。。&public class CheckPrinterState& & {& & & & public static bool CheckPrinter(string printerName1)& & & & {& & & & & & ManagementScope scope = new ManagementScope(@\"\\root\\cimv2\");& & & & & & scope.Connect();& & & & & & // Select Printers from WMI Object Collections& & & & & & ManagementObjectSearcher searcher = new',
blogTag:'c#,打印机状态',
blogUrl:'blog/static/',
isPublished:1,
istop:false,
modifyTime:4,
publishTime:9,
permalink:'blog/static/',
commentCount:0,
mainCommentCount:0,
recommendCount:0,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:false,
hostIntro:'。。。',
hmcon:'0',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}共有2088位成员   人气指数 -   最新排名 -
【话题】C#中如何判断打印机是否连接
20:06:06 来自:迪迪妈 浏览数:11次
用什么函数可以知道啊~~~~?
小妞妞回复于16日20点17分 
TheAres(班门斧)回复于
13:48:44 得分 100
可以用DirectoryServices&
IADSPrintQueueOperations.&
& 你具体参考这两个,都是C#的.&
& /groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=uV9zdJkMCHA.2392%40tkmsftngp04&rnum=2&
& /groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=rsFZSGsYCHA.1664%40cpmsftngxa06&
huilanlin回复于16日20点31分 
看一下,这文章
/default.aspx?scid=EN-US;q202480
C#builder的其他话题...
热门脚本语言:下次自动登录
现在的位置:
& 综合 & 正文
C#获取本机连接的打印机属性
MF3200 SeriesDirect : FalseDoCompleteFirst : TrueDriverName : Canon MF3200 SeriesEnableBIDI : TrueEnableDevQueryPrint : FalseErrorCleared : ErrorDescription : ErrorInformation : ExtendedDetectedErrorState : 0ExtendedPrinterStatus : 2Hidden : FalseHorizontalResolution : 600InstallDate : JobCountSinceLastReset : 0
//当前任务数KeepPrintedJobs : FalseLanguagesSupported : LastErrorCode : Local : FalseLocation : MarkingTechnology : MaxCopies : MaxNumberUp : MaxSizeSupported : MimeTypesSupported : Name :
MF3200 SeriesNaturalLanguagesSupported : Network : TruePaperSizesSupported : System.UInt16[]PaperTypesAvailable : Parameters : PNPDeviceID : PortName : USB001PowerManagementCapabilities : PowerManagementSupported : PrinterPaperNames : System.String[]PrinterState : 0
//打印机状态PrinterStatus : 3PrintJobDataType : RAWPrintProcessor : WinPrintPriority : 1Published : FalseQueued : FalseRawOnly : FalseSeparatorFile : ServerName : Shared : TrueShareName : CanonMF3SpoolEnabled : TrueStartTime : Status : UnknownStatusInfo : SystemCreationClassName : Win32_ComputerSystemSystemName : TimeOfLastReset : UntilTime : VerticalResolution : 600WorkOffline : False
//是否离线
/// &summary&
/// 打印机属性转换
/// &/summary&
/// &param name="PrinterDevice"&打印机名(DeviceID)&/param&
/// &param name="iCount"&当前任务数&/param&
/// &returns&打印机状态名字&/returns&
private PrinterStatus GetPrinterStat(string PrinterDevice,ref int iCount)
PrinterStatus ret = 0;
string path = @"win32_printer.DeviceId='" + PrinterDevice + "'";
ManagementObject printer = new ManagementObject(path);
printer.Get();
ret = (PrinterStatus)Convert.ToInt32(printer.Properties["PrinterStatus"].Value);
iCount = Convert.ToInt32(printer.Properties["JobCountSinceLastReset"].Value);
&&&&推荐文章:
【上篇】【下篇】using Susing System.Dusing System.Cusing System.Wusing System.Web.Susing System.Web.UI;using System.Web.UI.WebCusing System.Web.UI.WebControls.WebPusing System.Web.UI.HtmlCusing System.IO;using System.Runtime.InteropSusing System.T/// &summary&/// PrintPos 的摘要说明/// &/summary&public class PrintPos{&&&&&&& private FileStream fs =&&&&&&& [DllImport("kernel32.dll")]//调用系统API打印函数&&&&&&& public static extern IntPtr CreateFile&&&&&&&&&&& (&&&&&&&&&&& string FileName,&&&&&&&&& // file name&&&&&&& uint DesiredAccess,&&&&&& // access mode&&&&&&& uint ShareMode,&&&&&&&&&& // share mode&&&&&&& uint SecurityAttributes,& // Security Attributes&&&&&&& uint CreationDisposition, // how to create&&&&&&& uint FlagsAndAttributes,& // file attributes&&&&&&& int hTemplateFile&&&&&&&& // handle to template file&&&&&&&&&&& );&& &public PrintPos()&& &{&& &&& &//&& &&& &// TODO: 在此处添加构造函数逻辑&& &&& &//&& &}&&& /// &summary&&&& /// 开始打印,本地打印机ltp1 端口打印 调用方法:PrintPos.PrintPage("dsdfdsfdsfsdfdsfsdfdsfs");&&& /// &/summary&&&& /// &param name="strPos"&&/param&&&& /// &returns&&/returns&&&& public string PrintPage(string strPos)&&& {&&&&&&& IntPtr iHandle = CreateFile("LPT1", 0x, 0, 3, 0, 0);&&&&&&& //判断是否连接上打印机 -1为false&&&&&&& if (iHandle.ToInt32() == -1)&&&&&&& {&&&&&&&&&&& return "没有连接到打印机";&&&&&&& }&&&&&&& else&&&&&&& {&&&&&&&&&&& fs = new FileStream(iHandle, FileAccess.ReadWrite);&&&&&&&&&&& //StreamReader sr = new StreamReader(fs);&&&&&&&&&&& StreamWriter sw = new StreamWriter(fs, Encoding.Default);&&&&&&&&&&& sw.WriteLine(strPos, 0, 500);&&&&&&&&&&& sw.Close();&&&&&&&&&&& fs.Close();&&&&&&&&&&& return "已经成功连接打印机";&&&&&&& }&&& }}
阅读(...) 评论()

我要回帖

更多关于 打印机如何判断墨水 的文章

 

随机推荐