Advertisement
PoetralesanA

testes

Apr 9th, 2024
1,237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 0.92 KB | None | 0 0
  1. Private Sub CheckPrinter(ByVal printerName As String, ByVal labelName As Label)
  2.     Dim query As String = $"SELECT * FROM Win32_Printer WHERE Name LIKE '%{printerName}%'"
  3.     Dim searcher As New ManagementObjectSearcher(query)
  4.     Dim coll As ManagementObjectCollection = searcher.Get()
  5.  
  6.     For Each printer As ManagementObject In coll
  7.         Dim printerStatus As String = printer("PrinterStatus").ToString()
  8.         Dim paperStatus As String = printer("PrinterState").ToString()
  9.  
  10.         If printerStatus = "3" Then
  11.             If paperStatus = "5" Then
  12.                 labelName.Text = "ONLINE - OUT OF PAPER"
  13.                 labelName.ForeColor = Color.Yellow
  14.             Else
  15.                 labelName.Text = "ONLINE"
  16.                 labelName.ForeColor = Color.Green
  17.             End If
  18.         Else
  19.             labelName.Text = "OFFLINE"
  20.             labelName.ForeColor = Color.Red
  21.         End If
  22.     Next
  23. End Sub
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement