Bekijk de onderstaande video om te zien hoe je onze site als een web app op je startscherm installeert.
Opmerking: Deze functie is mogelijk niet beschikbaar in sommige browsers.
Sub try()
Dim AllePrinterData As Object, printernaam as string
printernaam = "naam van jouw printer hier, met UNC pad en zonder On....."
Set AllePrinterData = GetObject("winmgmts:\\.\root\CIMV2").Get("Win32_Printer='" & printernaam & "'")
Stop
End Sub
bron: https://docs.microsoft.com/en-us/windows/win32/cimwin32prov/win32-printer?redirectedfrom=MSDNNote
If you are retrieving PrinterStatus = 3 or PrinterState = 0, the printer driver may not be feeding accurate information into WMI. WMI retrieves the printer information from the spoolsv.exe process. It is possible the printer driver does not report its status to the spooler. In this case, Win32_Printer reports the printer as Idle.
Sub M_snb()
ReDim sn(27)
For Each it In GetObject("winmgmts:\\.\root\cimv2").ExecQuery("Select * from Win32_PrintJob")
sn(0) = "Caption" & vbTab & vbTab & it.Caption
sn(1) = "Description" & vbTab & it.Description
sn(2) = "InstallDate" & vbTab & it.InstallDate
sn(3) = "Name" & vbTab & vbTab & it.Name
sn(4) = "Status" & vbTab & vbTab & it.Status
sn(5) = "ElapsedTime" & vbTab & it.ElapsedTime
sn(6) = "JobStatus" & vbTab & it.JobStatus
sn(7) = "Notify" & vbTab & vbTab & it.Notify
sn(8) = "Owner" & vbTab & vbTab & it.Owner
sn(9) = "Priority" & vbTab & vbTab & it.Priority
sn(10) = "StartTime" & vbTab & it.StartTime
sn(11) = "TimeSubmitted" & vbTab & it.TimeSubmitted
sn(12) = "UntilTime" & vbTab & it.UntilTime
sn(14) = "DataType" & vbTab & vbTab & it.DataType
sn(15) = "Document" & vbTab & it.Document
sn(16) = "DriverName" & vbTab & it.DriverName
sn(17) = "HostPrintQueue" & vbTab & it.HostPrintQueue
sn(18) = "JobId" & vbTab & vbTab & it.JobId
sn(19) = "PagesPrinted" & vbTab & it.PagesPrinted
sn(23) = "Parameters" & vbTab & it.Parameters
sn(24) = "PrintProcessor" & vbTab & it.PrintProcessor
sn(25) = "Size" & vbTab & vbTab & it.Size
sn(26) = "StatusMask" & vbTab & it.StatusMask
sn(27) = "TotalPages" & vbTab & it.TotalPages
MsgBox Join(sn, vbLf)
Next
End Sub
Er is geen betrouwbare manier om te zien als een printer aan of uit staat (met WMI).
Als de printer niet netjes zijn status terugmeldt aan het spoolsv.exe process, zal je altijd status 3=idle krijgen bij de eigenschap "printerstatus".
bron: https://docs.microsoft.com/en-us/windows/win32/cimwin32prov/win32-printer?redirectedfrom=MSDN
Option Explicit
Public Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
Public Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, pDefault As PRINTER_DEFAULTS) As Long
Public Declare Function GetPrinter Lib "winspool.drv" Alias "GetPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, pPrinter As Byte, ByVal cbBuf As Long, pcbNeeded As Long) As Long
Public Declare Function ClosePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Public Type PRINTER_DEFAULTS
pDatatype As String
pDevMode As Long
DesiredAccess As Long
End Type
Public Const PRINTER_ACCESS_USE = &H8
Type PRINTER_INFO_2
pServerName As Long
pPrinterName As Long
pShareName As Long
pPortName As Long
pDriverName As Long
pComment As Long
pLocation As Long
pDevMode As Long
pSepFile As Long
pPrintProcessor As Long
pDatatype As Long
pParameters As Long
pSecurityDescriptor As Long
Attributes As Long
Priority As Long
DefaultPriority As Long
StartTime As Long
UntilTime As Long
Status As Long
cJobs As Long
AveragePPM As Long
End Type
Public Const ERROR_INSUFFICIENT_BUFFER = 122
Public Const PRINTER_STATUS_BUSY = &H200
Public Const PRINTER_STATUS_DOOR_OPEN = &H400000
Public Const PRINTER_STATUS_ERROR = &H2
Public Const PRINTER_STATUS_INITIALIZING = &H8000
Public Const PRINTER_STATUS_IO_ACTIVE = &H100
Public Const PRINTER_STATUS_MANUAL_FEED = &H20
Public Const PRINTER_STATUS_NO_TONER = &H40000
Public Const PRINTER_STATUS_NOT_AVAILABLE = &H1000
Public Const PRINTER_STATUS_OFFLINE = &H80
Public Const PRINTER_STATUS_OUT_OF_MEMORY = &H200000
Public Const PRINTER_STATUS_OUTPUT_BIN_FULL = &H800
Public Const PRINTER_STATUS_PAGE_PUNT = &H80000
Public Const PRINTER_STATUS_PAPER_JAM = &H8
Public Const PRINTER_STATUS_PAPER_OUT = &H10
Public Const PRINTER_STATUS_PAPER_PROBLEM = &H40
Public Const PRINTER_STATUS_PAUSED = &H1
Public Const PRINTER_STATUS_PENDING_DELETION = &H4
Public Const PRINTER_STATUS_PRINTING = &H400
Public Const PRINTER_STATUS_PROCESSING = &H4000
Public Const PRINTER_STATUS_TONER_LOW = &H20000
Public Const PRINTER_STATUS_USER_INTERVENTION = &H100000
Public Const PRINTER_STATUS_WAITING = &H2000
Public Const PRINTER_STATUS_WARMING_UP = &H10000
' ------------------------------------------------------
Function PrinterName()
If PrinterName = "" Then
PrinterName = Application.ActivePrinter
End If
Dim intOnPosition As Integer
intOnPosition = InStr(1, PrinterName, " op ")
If (intOnPosition > 0) Then
PrinterName = Left(PrinterName, intOnPosition - 1)
End If
End Function
Public Function CheckPrinter() As String
On Error GoTo Hell
Dim hPrinter As Long
Dim iByteBuffer As Long
Dim iBytesNeeded As Long
Dim tPI2 As PRINTER_INFO_2
Dim aPrinterInfo() As Byte
Dim Ret As Long
Dim sPrinterName As String
Dim tDefaults As PRINTER_DEFAULTS
'Use the default printer of Printers collection.
sPrinterName = PrinterName
'Set desired access security setting.
tDefaults.DesiredAccess = PRINTER_ACCESS_USE
'Call API to get a handle to the printer.
Ret = OpenPrinter(sPrinterName, hPrinter, tDefaults)
If Ret = 0 Then
CheckPrinter = "The system cannot open printer " & sPrinterName & ". Windows returned this error: " & Err.LastDllError
Exit Function
End If
'Init iBytesNeeded
iBytesNeeded = 0
'Clear the error object of any errors.
Err.Clear
'Determine the buffer size that is needed to get printer info.
Ret = GetPrinter(hPrinter, 2, 0&, 0&, iBytesNeeded)
' If Err.LastDllError = ERROR_INSUFFICIENT_BUFFER Then
'CheckPrinter = "The system failed to initialize the GetPrinter() API call due to insufficient buffer allocation."
'Else
ReDim aPrinterInfo(1 To iBytesNeeded)
iByteBuffer = iBytesNeeded
'Call GetPrinter to get the status.
Ret = GetPrinter(hPrinter, 2, aPrinterInfo(1), iByteBuffer, iBytesNeeded)
If Ret = 0 Then
CheckPrinter = "The system could not determine the printer Status. Windows printing subsystem returned this error:" & Err.LastDllError
Else
'Copy contents of printer status byte array into a
'PRINTER_INFO_2 structure to separate the individual elements.
CopyMemory tPI2, aPrinterInfo(1), Len(tPI2)
If (tPI2.Status And PRINTER_STATUS_BUSY) Then CheckPrinter = "The printer returned a status of: Busy"
If (tPI2.Status And PRINTER_STATUS_DOOR_OPEN) Then CheckPrinter = "The printer returned a status of: Printer Door Open"
If (tPI2.Status And PRINTER_STATUS_ERROR) Then CheckPrinter = "The printer returned a status of: Printer Error"
If (tPI2.Status And PRINTER_STATUS_NO_TONER) Then CheckPrinter = "The printer returned a status of: No Toner"
If (tPI2.Status And PRINTER_STATUS_NOT_AVAILABLE) Then CheckPrinter = "The printer returned a status of: Not Available"
If (tPI2.Status And PRINTER_STATUS_OFFLINE) Then CheckPrinter = "The printer returned a status of: Off Line"
If (tPI2.Status And PRINTER_STATUS_OUT_OF_MEMORY) Then CheckPrinter = "The printer returned a status of: Out of Memory"
If (tPI2.Status And PRINTER_STATUS_PAGE_PUNT) Then CheckPrinter = "The printer returned a status of: Page Punt"
If (tPI2.Status And PRINTER_STATUS_PAPER_JAM) Then CheckPrinter = "The printer returned a status of: Paper Jam"
If (tPI2.Status And PRINTER_STATUS_PAPER_OUT) Then CheckPrinter = "The printer returned a status of: Paper Out"
If (tPI2.Status And PRINTER_STATUS_PAPER_PROBLEM) Then CheckPrinter = "The printer returned a status of: Page Problem"
If (tPI2.Status And PRINTER_STATUS_PAUSED) Then CheckPrinter = "The printer returned a status of: Paused"
End If
'End If
'Close the printer handle.
ClosePrinter hPrinter
Hell:
End Function
Option Explicit
Private Function PrinterWorkOffline(sPrinter) As Boolean
PrinterWorkOffline = CreateObject("WbemScripting.SWbemLocator").ConnectServer(".", "root\cimv2").ExecQuery("SELECT * FROM Win32_Printer WHERE Name = '" & sPrinter & "'").itemindex(0).workoffline
End Function
Public Sub Main()
Dim bWorkOffline As Boolean
bWorkOffline = PrinterWorkOffline("EPSON Stylus SX600FW") 'printername
End Sub
We gebruiken essentiële cookies om deze site te laten werken, en optionele cookies om de ervaring te verbeteren.