Re: Print error alerts by D
D
Sun May 02 16:21:33 CDT 2004
Below is some VB code that can be compiled with vbc compiler under Framework
1.1 install. The compiler is under
%windir%\Microsoft.Net\Framework\v1.1.4322\ on my pc. The compile command
is:
vbc /r:system.dll,system.management.dll,system.windows.forms.dll
PrintTest.vb
This will create an exe file called PrintTest.exe. Note: you will have to
either compile this in the v1.1.4322 directory or add a path to this
directory, because this is where the referenced .dll programs reside.
When you execute this program with some part of a distinct printer name as a
command line argument, it will give you an alert box when a printer error
occurs.
The hard part about using this may be in using the security wizards that
come with framework as far as what you allow for local machine code.
========= here's the code
' PrintTest.vb
' vbc /r:System.dll,System.Management.dll,System.Windows.Forms.dll
PrintTest.vb
Imports System
Imports System.Threading
Imports System.Management
Class PrintTest
Shared strPrn as string
Shared Sub Main(ByVal args() as string)
Try
strPrn = args(0)
Console.WriteLine("Checking " & strPrn & " printer")
' 30000 is for 30 second timer
Dim Timer1 as new Timer(new TimerCallback(AddressOf
CheckPrinter), nothing, 0, 30000)
Console.WriteLine("Press Enter to close window....")
Console.Read()
Catch e as system.exception
Console.writeLine("Enter a printer name as in: PrintTest LP")
End Try
End Sub
Shared Sub CheckPrinter(state as Object)
Static LPErrCount as integer
'Console.WriteLine("Checking Status" & LPErrCount.tostring)
'uncomment for debugging
Dim Query as String = "SELECT * FROM Win32_PrintJob"
Dim JobQuery as new ManagementObjectSearcher(Query)
Dim Jobs as ManagementObjectCollection = JobQuery.Get
Dim Job as ManagementObject
Dim intTest as integer
Dim intJobs as integer = 0
for each Job in Jobs
intTest = Job("Caption").indexof(strPrn)
if intTest >= 0 then
' increment intJobs if any jobs for this printer found
intJobs += 1
intTest = Job("Status").indexof("Error")
if intTest >= 0 then
LPErrCount += 1
if LPErrCount = 5 then
System.Windows.Forms.MessageBox.Show("Error on " &
strPrn & " Printer")
LPErrCount = 0
end if
if LPErrCount > 960 then
' stop after 8 hours of checking printer, nobody is
home
stop
end if
else
LPErrCount = 0
end if
end if
next
if intJobs < 1 then
' no jobs found in queue for this printer, so reset error
counter
LPErrCount = 0
end if
End Sub
End Class
Hope you can use this
- Dave Carroll
"Bob Cobb" <bob@home.com> wrote in message
news:OlWjZicLEHA.2736@TK2MSFTNGP11.phx.gbl...
> We are running SBS2K, and many printers are shared off this server.
> There is a packing slip printer in the warehouse that often goes offline,
> has a paper jam, or runs out of paper, and the warehouse staff never seem
to
> notice in a reasonable amount of time.
> I want to set an alert, so that when the printer goes off line, or there
is
> a paper error, the alert can net send a message to a particular PC, so a
> phone call can be made..
>
> We managed to get the basics working, and set it so that when the counter
is
> greater than 0, a message would be sent. The problem we have is with
> resetting the counter.
> Currently, the counter is set to 30 after a few errors, and every time it
> polls, it sends a message, even after the problem is fixed. We have had to
> stop the alert, but when we restart the alert, it sends more messages, as
> the counter is still 30.
>
> Can youone suggest anything?
>
> Thanks
>
> Bob
>
>