以下代码供参考,可实现楼主需要的部分功能:
$intPrinters = 1
$objWMIService = ObjGet("winmgmts:\\.\root\CIMV2")
$colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_Printer")
For $objItem In $colItems
if $objItem.Queued > 0 or $objItem.PrinterStatus <> 3 or $objItem.PrinterState <> 0 Then
ConsoleWrite("Printers on " _
& $objItem.name & ", Printer Number: " & $intPrinters & @LF & _
"====================================" & @LF & _
"Availability: " & $objItem.Availability & @LF & _
"Description: " & $objItem.Description & @LF & _
"Printer: " & $objItem.DeviceID & @LF & _
"Driver Name: " & $objItem.DriverName & @LF & _
"Port Name: " & $objItem.PortName & @LF & _
"Printer State: " & $objItem.PrinterState & @LF & _
"Printer Status: " & $objItem.PrinterStatus & @LF & _
"PrintJobDataType: " & $objItem.PrintJobDataType & @LF & _
"Print Processor: " & $objItem.PrintProcessor & @LF & _
"Spool Enabled: " & $objItem.SpoolEnabled & @LF & _
"Separator File: " & $objItem.SeparatorFile & @LF & _
"Queued: " & $objItem.Queued & @LF & _
"Status: " & $objItem.Status & @LF & _
"StatusInfo: " & $objItem.StatusInfo & @LF & _
"Published: " & $objItem.Published & @LF & _
"Shared: " & $objItem.Shared & @LF & _
"ShareName: " & $objItem.ShareName & @LF & _
"Direct: " & $objItem.Direct & @LF & _
"Location: " & $objItem.Location & @LF & _
"Priority: " & $objItem.Priority & @LF & _
"Work Offline: " & $objItem.WorkOffline & @LF & _
"Horizontal Res: " & $objItem.HorizontalResolution & @LF & _
"Vertical Res: " & $objItem.VerticalResolution )
ConsoleWrite(@lf & "************************************************************************************" & @lf)
EndIf
$intPrinters = $intPrinters + 1
Next
执行结果如下:
Printer: \\IP\HP LaserJet P1007
Driver Name: HP LaserJet P1007
Port Name: USB001 ; (端口名,可获取后进行选择)
Printer State: 16
Printer Status: 1 ;(1为联机,其它的状态可能要自己找WMI的资料看看了。。)
PrintJobDataType: RAW
Print Processor: HP1006S
Spool Enabled: True
Separator File:
Queued: False
Status: Error
StatusInfo:
Published: False
Shared: True
ShareName: HPLaserJ
Direct: False
Location:
Priority: 1
Work Offline: False ;(打印机是否在线)
Horizontal Res: 600
Vertical Res: 600
************************************************************************************
|