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

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
>
>



Re: Print error alerts by Bob

Bob
Mon May 03 04:56:48 CDT 2004

Thanks for your help.
I tried to compile the code, by saving it as PrintTest.vb.
I Ran you command: vbc
/r:system.dll,system.management.dll,system.windows.forms.dll PrintTest.vb,
and got the following errors:
(I would think that I need to specify the printer somewhere in your code,
but I couldn't find where? I checked the .Net Wizard, and insured that
LocalMachine has Full Trust)

for Microsoft (R) .NET Framework version 1.1.4322.573
Copyright (C) Microsoft Corporation 1987-2002. All rights reserved.

C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\PrintTest.vb(3) : error
BC30188: Declaration expected.

PrintTest.vb
~~~~~~~~~
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\PrintTest.vb(4) : error
BC30465: 'Imports' statements must precede any declarations.

Imports System
~~~~~~~
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\PrintTest.vb(5) : error
BC30465: 'Imports' statements must precede any declarations.

Imports System.Threading
~~~~~~~
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\PrintTest.vb(6) : error
BC30465: 'Imports' statements must precede any declarations.

Imports System.Management
~~~~~~~
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\PrintTest.vb(15) : error
BC30201: Expression expected.

Dim Timer1 as new Timer(new TimerCallback(AddressOf
~
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\PrintTest.vb(16) : error
BC30455: Argument not specified for parameter 'state' of 'Public Shared Sub
CheckPrinter(state As Object)'.

CheckPrinter), nothing, 0, 30000)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\PrintTest.vb(16) : error
BC30800: Method arguments must be enclosed in parentheses.

CheckPrinter), nothing, 0, 30000)
~
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\PrintTest.vb(16) : error
BC30205: End of statement expected.

CheckPrinter), nothing, 0, 30000)
~~~~~~~~~~~~~~~~~~~~~
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\PrintTest.vb(42) : error
BC30201: Expression expected.

System.Windows.Forms.MessageBox.Show("Error on " &
~
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\PrintTest.vb(43) : error
BC30454: Expression is not a method.

strPrn & " Printer")
~~~~~~
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\PrintTest.vb(43) : error
BC30201: Expression expected.

strPrn & " Printer")
~
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\PrintTest.vb(43) : error
BC30800: Method arguments must be enclosed in parentheses.

strPrn & " Printer")
~
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\PrintTest.vb(48) : error
BC30451: Name 'home' is not declared.

home
~~~~
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\PrintTest.vb(58) : error
BC30451: Name 'counter' is not declared.

counter
~~~~~~~

This may be all beyond me, but any help you can provide would be great.
Thanks for the time you have spent so far.

Regards

Bob

"D Carroll" <dave@rcsx.com> wrote in message ...

> 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.



Re: Print error alerts by D

D
Mon May 03 22:27:53 CDT 2004

Bob,
The second comment that was supposed to be all on one line was extended to
the third line when I pasted the code into Outlook. If you look at the
third line of PrintTest.vb, where "PrintTest.vb" is by itself - that should
be on the tail end of the second line. I was just adding the compile command
as a comment in the code file. The first non-commented line in the code
should be Imports System.

I have made the printer name an argument on the command line that executes
the program. When you start the program by typing PrintTest.exe HPLJ, the
code will look for a printer device name with HPLJ in it.

D Carroll
"Bob Cobb" <bob@home.com> wrote in message
news:uTTE4TPMEHA.556@TK2MSFTNGP10.phx.gbl...
> Thanks for your help.
> I tried to compile the code, by saving it as PrintTest.vb.
> I Ran you command: vbc
> /r:system.dll,system.management.dll,system.windows.forms.dll PrintTest.vb,
> and got the following errors:
> (I would think that I need to specify the printer somewhere in your code,
> but I couldn't find where? I checked the .Net Wizard, and insured that
> LocalMachine has Full Trust)
>
> for Microsoft (R) .NET Framework version 1.1.4322.573
> Copyright (C) Microsoft Corporation 1987-2002. All rights reserved.
>
> C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\PrintTest.vb(3) : error
> BC30188: Declaration expected.
>
> PrintTest.vb
> ~~~~~~~~~
> C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\PrintTest.vb(4) : error
> BC30465: 'Imports' statements must precede any declarations.
>
> Imports System
> ~~~~~~~
> C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\PrintTest.vb(5) : error
> BC30465: 'Imports' statements must precede any declarations.
>
> Imports System.Threading
> ~~~~~~~
> C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\PrintTest.vb(6) : error
> BC30465: 'Imports' statements must precede any declarations.
>
> Imports System.Management
> ~~~~~~~
> C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\PrintTest.vb(15) : error
> BC30201: Expression expected.
>
> Dim Timer1 as new Timer(new TimerCallback(AddressOf
> ~
> C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\PrintTest.vb(16) : error
> BC30455: Argument not specified for parameter 'state' of 'Public Shared
Sub
> CheckPrinter(state As Object)'.
>
> CheckPrinter), nothing, 0, 30000)
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\PrintTest.vb(16) : error
> BC30800: Method arguments must be enclosed in parentheses.
>
> CheckPrinter), nothing, 0, 30000)
> ~
> C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\PrintTest.vb(16) : error
> BC30205: End of statement expected.
>
> CheckPrinter), nothing, 0, 30000)
> ~~~~~~~~~~~~~~~~~~~~~
> C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\PrintTest.vb(42) : error
> BC30201: Expression expected.
>
> System.Windows.Forms.MessageBox.Show("Error on " &
> ~
> C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\PrintTest.vb(43) : error
> BC30454: Expression is not a method.
>
> strPrn & " Printer")
> ~~~~~~
> C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\PrintTest.vb(43) : error
> BC30201: Expression expected.
>
> strPrn & " Printer")
> ~
> C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\PrintTest.vb(43) : error
> BC30800: Method arguments must be enclosed in parentheses.
>
> strPrn & " Printer")
> ~
> C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\PrintTest.vb(48) : error
> BC30451: Name 'home' is not declared.
>
> home
> ~~~~
> C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\PrintTest.vb(58) : error
> BC30451: Name 'counter' is not declared.
>
> counter
> ~~~~~~~
>
> This may be all beyond me, but any help you can provide would be great.
> Thanks for the time you have spent so far.
>
> Regards
>
> Bob
>
> "D Carroll" <dave@rcsx.com> wrote in message ...
>
> > 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.
>
>



Re: Print error alerts by D

D
Mon May 03 22:47:24 CDT 2004

Bob, here is another copy of the code, that when you look at full screen
should not have any lines wrapped.

' 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


- D Carroll



Re: Print error alerts by D

D
Mon May 03 23:07:22 CDT 2004

Bob, a few of the lines are still screwed up after looking at them on the
newsgroup:
1) 'vbc /r:System.dll,System.Management.dll,System.Windows.Forms.dll
PrintTest.vb
2) Dim Timer1 as new Time(new TimerCallback(AddressOf
CheckPrinter),nothing,0,30000)
3) System.Windows.Forms.MessageBox.Show("Error on " & strPrn & " Printer")
4) ' stop after 8 hours of checking printer, nobody is home
5) ' no jobs found in queue for this printer, so reset error counter

These five lines are all supposed to be on the one line each, and the
wrapping of the lines by Outlook is causing the errors you are getting on
the compile.
D Carroll



Re: Print error alerts by Bob

Bob
Mon May 03 23:58:08 CDT 2004

That worked perfectly.
Thankyou very much Dave!

Bob

"D Carroll" <dc9902@yahoo.com> wrote in message ...
> Bob, a few of the lines are still screwed up after looking at them on the
> newsgroup:
<snip>
> These five lines are all supposed to be on the one line each, and the
> wrapping of the lines by Outlook is causing the errors you are getting on
> the compile.
> D Carroll
>
>