检查打印机是否为【脱机】状态。各种状态提取参照!-litao
Access软件网QQ交流学习群(群号码198465573),欢迎您的加入!
首页 >技术文章> Access数据库-模块/函数/VBA


检查打印机是否为【脱机】状态。各种状态提取参照!

发表时间:2014/10/9 11:17:06 评论(1) 浏览(9762)  评论 | 加入收藏 | 复制
   
摘 要:通过检查【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群(群号:198465573)
 
 相关文章
[access报表]指定打印机进行报表打印   【竹笛  2004/5/18】
[access报表]获得某一台网络打印机有几份等待打印的报表  【fan0217  2008/9/4】
在access中更改报表的打印机\纸张设置  【王樵民  2011/9/1】
【译文】如何检索已安装打印机的列表  【周芳  2013/12/31】
常见问答
技术分类
相关资源
文章搜索
关于作者

litao

文章分类

文章存档

友情链接