Alan Gillott wrote:
> I am struggling to get Windows Instrumentation to work with printers using
> either vbScript or dotnet. However the problem I am trying to resolve is not
> straight forward. It involves multiple hardware (suppliers) for a printer,
> NAS device, (I stupidly bought two) and a Wireless Router and lots of
> emotion: wife who expects everything to work, evil stepdaughter and IT dude
> husband who designs and builds software and who usually waves these issues
> off to IT support - except I am the IT support dude and I am dying in an
> emotional morass.
>
> Setup.
>
> Several Laptops, wireless links to an ADSL Linksys (which has its own
> issues), ethernet connection to a Maxtor NAS device which in turn drives a
> USB Laser Printer (Brother).
>
> In my innocence I saw this as a way to share the houshold printers. Alas &
> alak, it doesn't support bi-directional printers so no pretty color printers
> & scanners. Grrr.
>
If you cannot get an elegant solution to your problem have you
considered configuring the printer on one of the computers at your
house and sharing it from that computer? Of course that computer would
need to be turned on to act as the print server.
> 2) I have a VB.NET program, not used in anger though, that can detect
> hibernation. This checks the state of the Maxtor and logs everyone on as
> needed. Works a dream BUT
>
> I cannot get my head around Woindows Instrumentation and figure out the text
> string I need to check it's status (my printers and faxes folder can).
> Neither in vbScript nor VB.Net.
>
> The Maxtor is an embedded NT, appears as a node on my peer to peer network
> but the Printer is not "owned" by the Maxtor but is a wierd type of USB
> device that doesn't have a USB hub as seen by each Laptop (I think that's
> why I have to recycle it) The Laptop clients detect it's loss but not it's
> reappearance. I want at least to be able to flash lights on Laptops that
> can't see it properly - my family might just be motivated to recycle it
> before printing 100 page thesises which vanish into some printing black
> hole.
>
> 1) anyone have any idea what magic string I need to give to instrumentation
> to check the Printer's status? All the books give lots of examples of
> everything but printers.
>
Alan,
Please see my comment about printer sharing above. There are two
properties of the Win32_Printer class that may help you. You can read
more about the Win32_Printer class here:
http://msdn.microsoft.com/library/de...start_page.asp
On that page open the WMI Reference > WMI Classes > Win32 Classes >
Computer System > Win32_Printer
Another good way to learn about the various WMI Classes and properties
that you can read from devices you can use the Scripting Guys'
Scriptomatic utility available here:
http://www.microsoft.com/downloads/d...displaylang=en
Here are two functions that return the status of a printer. The second
function will not work on Windows 2000 or NT, but the first one will.
The first parameter for each function is the computer name you are
querying, and the second is the device ID of your printer as a string.
Note that this is the name your printer driver gives the printer, not
the printer share name.
-------------------------
MsgBox GetPrinterStatus (".","YourPrinter")
Function GetPrinterStatus(strComputer, strPrinterDevID)
'Accepts a computer name and printer device ID as string parameters
'Returns the printer status as a string
Dim intStatus: intStatus = 0
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
On Error Resume Next
Err.Clear
Set objWMIService = GetObject("winmgmts:\\" & strComputer &
"\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Printer
Where DeviceID = '" _
& strPrinterDevID & "'", "WQL", wbemFlagReturnImmediately + _
wbemFlagForwardOnly)
If Err.Number = 0 Then
For Each objItem In colItems
intStatus = objItem.PrinterStatus
Next
Else
GetPrinterStatus = "Error Getting Printer Status"
End If
Select Case intStatus
Case 1
GetPrinterStatus = "Other"
Case 2
GetPrinterStatus = "Unknown"
Case 3
GetPrinterStatus = "Idle"
Case 4
GetPrinterStatus = "Printing"
Case 5
GetPrinterStatus = "Warmup"
Case 6
GetPrinterStatus = "Stopped Printing"
Case 7
GetPrinterStatus = "Offline"
Case 0
GetPrinterStatus = "Error Getting Printer Status"
End Select
End Function
MsgBox GetExtendedPrinterStatus(".","YourPrinter")
Function GetExtendedPrinterStatus(strComputer, strPrinterDevID)
'Accepts a computer name and printer device ID as string parameters
'Returns the extended printer status as a string
'This function is not supported on Windows 2000 & NT
Dim intStatus: intStatus = 0
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
On Error Resume Next
Err.Clear
Set objWMIService = GetObject("winmgmts:\\" & strComputer &
"\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Printer
Where DeviceID = '" _
& strPrinterDevID & "'", "WQL", wbemFlagReturnImmediately + _
wbemFlagForwardOnly)
If Err.Number = 0 Then
For Each objItem In colItems
intStatus = objItem.ExtendedPrinterStatus
Next
Else
GetExtendedPrinterStatus = "Error Getting Printer Status"
End If
Select Case intStatus
Case 1
GetExtendedPrinterStatus = "Other"
Case 2
GetExtendedPrinterStatus = "Unknown"
Case 3
GetExtendedPrinterStatus = "Idle"
Case 4
GetExtendedPrinterStatus = "Printing"
Case 5
GetExtendedPrinterStatus = "Warmup"
Case 6
GetExtendedPrinterStatus = "Stopped Printing"
Case 7
GetExtendedPrinterStatus = "Offline"
Case 8
GetExtendedPrinterStatus = "Paused"
Case 9
GetExtendedPrinterStatus = "Error"
Case 10
GetExtendedPrinterStatus = "Busy"
Case 11
GetExtendedPrinterStatus = "Not Available"
Case 12
GetExtendedPrinterStatus = "Waiting"
Case 13
GetExtendedPrinterStatus = "Processing"
Case 14
GetExtendedPrinterStatus = "Initialization"
Case 15
GetExtendedPrinterStatus = "Power Save"
Case 16
GetExtendedPrinterStatus = "Pending Deletion"
Case 17
GetExtendedPrinterStatus = "I/O Active"
Case 18
GetExtendedPrinterStatus = "Manual Feed"
Case 0
GetExtendedPrinterStatus = "Error Getting Printer Status"
End Select
End Function
-------------------------
--
James Garringer