检查打印机是否为【脱机】状态。各种状态提取参照!
时 间: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高效办公】统计当...(06.30)
- 【Access高效办公】用复选...(06.24)
- 根据变化的日期来自动编号的示例...(06.20)
- 【Access高效办公】按日期...(06.12)
- 合并列数据到一个文本框的示例;...(05.06)
- 通过命令按钮让Access列表...(04.24)
- 【Access高效办公】统计当...(03.11)
- 【Access Inputbo...(03.03)
- 按回车键后光标移动到下一条记录...(02.12)

学习心得
最新文章
- Access快速开发平台--执行有...(07.03)
- 【Access高效办公】统计当月之...(06.30)
- 【Access高效办公】用复选框控...(06.24)
- 根据变化的日期来自动编号的示例;根...(06.20)
- Access快速开发平台--Acc...(06.16)
- 【Access高效办公】按日期区间...(06.12)
- Access快速开发平台--生成复...(06.07)
- 仓库管理实战课程(25)-导航菜单...(06.06)
- 仓库管理实战课程(24)-库存月结...(06.05)
- 分享一个简单的X氏家谱小示例(06.04)