检查打印机是否为【脱机】状态。各种状态提取参照!
时 间:2014-10-09 11:17:06
作 者:litao ID:37995 城市:上海
摘 要:通过检查【Win32_Printer】的 Attributes 属性 的(二进制 1024) 位的状态【PRINTER_ATTRIBUTE_WORK_OFFLINE】: 1为脱机,0为联机
Attributes属性 的各个二进制位,代表了打印机各种状态,可通过公式提取出来:
如:提取其1024位的状态: (Int(objx.Attributes / 1024)) Mod 2
正 文:
通过检查【Win32_Printer】的 Attributes 属性 的(二进制 1024) 位的状态【PRINTER_ATTRIBUTE_WORK_OFFLINE】: 1为脱机,0为联机
Attributes属性 的各个二进制位,代表了打印机各种状态,可通过公式提取出来:
如:提取其1024位的状态: (Int(objx.Attributes / 1024)) Mod 2
‘========VBA代码================
Private Const 分隔符 As String = ",", 引号 As String = "'"
Sub cs001()
MsgBox RPrinList
End Sub
Public Function RPrinList(Optional ByRef 默认打印机) As String '返回所有联机的打印机
Dim Str As String
If Printers.Count < 1 Then Exit Function '没有打印机
Str = ""
Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colPrinters = objWMI.ExecQuery("Select * from Win32_Printer")
For Each objx In colPrinters
If (Int(objx.Attributes / 1024)) Mod 2 = 0 Then ' 检查是否脱机: PRINTER_ATTRIBUTE_WORK_OFFLINE:
Str = Str & 分隔符 & 引号 & objx.name & 引号
End If
Next
If Str <> "" Then Str = Mid(Str, 2)
RPrinList = Str
If Printers.Count = 1 Then 默认打印机 = Str ’只有一台打印机,返回该打印机名作为 默认打印机
End Function
'==============Attributes 属性 说明=======================
AttributesData type: uint32Access type: Read-only
Bitmap of attributes for a Windows-based printing device.
Value used to set the bit | Meaning |
---|---|
PRINTER_ATTRIBUTE_QUEUED1 (0x1) |
Queued Print jobs are buffered and queued. |
PRINTER_ATTRIBUTE_DIRECT2 (0x2) |
Direct Document to be sent directly to the printer. This value is used if print jobs are not queued correctly. |
PRINTER_ATTRIBUTE_DEFAULT4 (0x4) |
Default Default printer on a computer. |
PRINTER_ATTRIBUTE_SHARED8 (0x8) |
Shared Available as a shared network resource. |
PRINTER_ATTRIBUTE_NETWORK16 (0x10) |
Network Attached to a network. If both Local and Network bits are set, this indicates a network printer. |
PRINTER_ATTRIBUTE_HIDDEN32 (0x20) |
Hidden Hidden from some users on the network. |
PRINTER_ATTRIBUTE_LOCAL64 (0x40) |
Local Directly connected to a computer. If both Local and Network bits are set, this indicates a network printer. |
PRINTER_ATTRIBUTE_ENABLEDEVQ128 (0x80) |
EnableDevQ Enable the queue on the printer if available. |
PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS256 (0x100) |
KeepPrintedJobs Spooler should not delete documents after they are printed. |
PRINTER_ATTRIBUTE_DO_COMPLETE_FIRST512 (0x200) |
DoCompleteFirst Start jobs that are finished spooling first. |
PRINTER_ATTRIBUTE_WORK_OFFLINE1024 (0x400) |
WorkOffline Queue print jobs when a printer is not available. |
PRINTER_ATTRIBUTE_ENABLE_BIDI2048 (0x800) |
EnableBIDI Enable bidirectional printing. |
PRINTER_ATTRIBUTE_RAW_ONLY4096 (0x1000) |
Allow only raw data type jobs to be spooled. |
PRINTER_ATTRIBUTE_PUBLISHED8192 (0x2000) |
Published Published in the network directory service. |
Access软件网官方交流QQ群 (群号:54525238) Access源码网店
常见问答:
技术分类:
源码示例
- 【源码QQ群号19834647...(12.17)
- Access对子窗体数据进行批...(10.30)
- 最精简的组合框行来源数据快速输...(10.25)
- Access仿平台的多值选择器...(10.24)
- 【Access日期区间段查询】...(10.22)
- 【Access源码示例】VBA...(10.12)
- Access累乘示例,Acce...(10.09)
- 数值8.88,把整数8去掉,转...(10.08)
- 【Access自定义函数】一个...(09.30)
- 【Access选项卡示例】Ac...(09.09)
学习心得
最新文章
- Access快速开发平台--对上传...(11.22)
- Access快速开发平台企业版--...(11.18)
- 不会用多表联合查询,多表查询没结果...(11.16)
- 【案例分享】主键字段值含有不间断空...(11.16)
- Access快速开发平台--后台D...(11.14)
- 微软Access邀测新Monaco...(11.12)
- Access列表框左右互选、列表框...(11.11)
- 高效率在导入数据前删除记录(11.10)
- Access报价单转订单示例代码(11.08)
- Access系统自带的日期选择器不...(11.08)