PC Review


Reply
Thread Tools Rate Thread

How to check a printer's availability

 
 
=?Utf-8?B?Y2xhcmE=?=
Guest
Posts: n/a
 
      27th Jul 2007
Hi all,

Two bad things happened during my worksheet printing:

the first time the notepad is not connected to network before I click the
print button, but after I connect the notepad, the worksheet could not be
printed out correctly.
the second time the printer is out of paper before I click the print button,
same thing happened as the first time.

So I would like to know how to check the availability of a printer before
printing?

Thank you very much.

Clara


--
thank you so much for your help
 
Reply With Quote
 
 
 
 
=?Utf-8?B?dXJrZWM=?=
Guest
Posts: n/a
 
      27th Jul 2007
"clara" wrote:

> Hi all,
>
> Two bad things happened during my worksheet printing:
>
> the first time the notepad is not connected to network before I click the
> print button, but after I connect the notepad, the worksheet could not be
> printed out correctly.
> the second time the printer is out of paper before I click the print button,
> same thing happened as the first time.
>
> So I would like to know how to check the availability of a printer before
> printing?
>
> Thank you very much.
>
> Clara
>
>


I'm not sure this is exactly what you need, but you can get some information
about printer status using WMI. You need administrator privileges to run it:


Sub WMITest()

'get active printer
strPrinterName = Application.ActivePrinter

'connect to WMI on local computer
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")

'enumerate printers
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer")

'Printer status:
'1 Other
'2 Unknown
'3 Idle
'4 Printing
'5 Warmup
'6 Stopped printing
'7 Offline

'get active printer status
For Each objPrinter In colInstalledPrinters

If InStr(strPrinterName, objPrinter.Name) Then
Debug.Print objPrinter.Name
If objPrinter.PrinterStatus = 1 _
Or objPrinter.PrinterStatus = 2 Then
Debug.Print "Printer not responding"
Else
Debug.Print "Printer status OK"
End If
End If

Next


End Sub


Hope this helps.

--
urkec
 
Reply With Quote
 
=?Utf-8?B?Y2xhcmE=?=
Guest
Posts: n/a
 
      27th Jul 2007
Hi Urkec,

It works well! Before I printign, now I can know the state of the printer.
Now, Could you tell me What is WMI and How can we take advantage of it?

Thank you again!

Clara
--
thank you so much for your help


"urkec" wrote:

> "clara" wrote:
>
> > Hi all,
> >
> > Two bad things happened during my worksheet printing:
> >
> > the first time the notepad is not connected to network before I click the
> > print button, but after I connect the notepad, the worksheet could not be
> > printed out correctly.
> > the second time the printer is out of paper before I click the print button,
> > same thing happened as the first time.
> >
> > So I would like to know how to check the availability of a printer before
> > printing?
> >
> > Thank you very much.
> >
> > Clara
> >
> >

>
> I'm not sure this is exactly what you need, but you can get some information
> about printer status using WMI. You need administrator privileges to run it:
>
>
> Sub WMITest()
>
> 'get active printer
> strPrinterName = Application.ActivePrinter
>
> 'connect to WMI on local computer
> strComputer = "."
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" _
> & strComputer & "\root\cimv2")
>
> 'enumerate printers
> Set colInstalledPrinters = objWMIService.ExecQuery _
> ("Select * from Win32_Printer")
>
> 'Printer status:
> '1 Other
> '2 Unknown
> '3 Idle
> '4 Printing
> '5 Warmup
> '6 Stopped printing
> '7 Offline
>
> 'get active printer status
> For Each objPrinter In colInstalledPrinters
>
> If InStr(strPrinterName, objPrinter.Name) Then
> Debug.Print objPrinter.Name
> If objPrinter.PrinterStatus = 1 _
> Or objPrinter.PrinterStatus = 2 Then
> Debug.Print "Printer not responding"
> Else
> Debug.Print "Printer status OK"
> End If
> End If
>
> Next
>
>
> End Sub
>
>
> Hope this helps.
>
> --
> urkec

 
Reply With Quote
 
=?Utf-8?B?dXJrZWM=?=
Guest
Posts: n/a
 
      27th Jul 2007
"clara" wrote:

> Hi Urkec,
>
> It works well! Before I printign, now I can know the state of the printer.
> Now, Could you tell me What is WMI and How can we take advantage of it?
>


WMI stands for Windows Management Instrumentation. It is used mostly for
system administration (getting system information, monitoring etc). It is a
set of classes (like Win32_Printer) that represent just about any computer
component you can think of. It can be very useful.

Hope this helps. I'm sure you can google a much better answer.

--
urkec
 
Reply With Quote
 
Tom
Guest
Posts: n/a
 
      31st Jul 2009
I think that this would be useful to me, but every time I run it, I get a
status return of 3, even when the printer is turned off.

Is there something I need in addition to this script?

Thanks for the help.

"urkec" wrote:

> "clara" wrote:
>
> > Hi all,
> >
> > Two bad things happened during my worksheet printing:
> >
> > the first time the notepad is not connected to network before I click the
> > print button, but after I connect the notepad, the worksheet could not be
> > printed out correctly.
> > the second time the printer is out of paper before I click the print button,
> > same thing happened as the first time.
> >
> > So I would like to know how to check the availability of a printer before
> > printing?
> >
> > Thank you very much.
> >
> > Clara
> >
> >

>
> I'm not sure this is exactly what you need, but you can get some information
> about printer status using WMI. You need administrator privileges to run it:
>
>
> Sub WMITest()
>
> 'get active printer
> strPrinterName = Application.ActivePrinter
>
> 'connect to WMI on local computer
> strComputer = "."
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" _
> & strComputer & "\root\cimv2")
>
> 'enumerate printers
> Set colInstalledPrinters = objWMIService.ExecQuery _
> ("Select * from Win32_Printer")
>
> 'Printer status:
> '1 Other
> '2 Unknown
> '3 Idle
> '4 Printing
> '5 Warmup
> '6 Stopped printing
> '7 Offline
>
> 'get active printer status
> For Each objPrinter In colInstalledPrinters
>
> If InStr(strPrinterName, objPrinter.Name) Then
> Debug.Print objPrinter.Name
> If objPrinter.PrinterStatus = 1 _
> Or objPrinter.PrinterStatus = 2 Then
> Debug.Print "Printer not responding"
> Else
> Debug.Print "Printer status OK"
> End If
> End If
>
> Next
>
>
> End Sub
>
>
> Hope this helps.
>
> --
> urkec

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Urgent:How to Check availability of web service nRk Microsoft C# .NET 3 5th Apr 2008 02:05 AM
domain name availability check Puja Microsoft C# .NET 5 8th Jun 2007 05:50 PM
Check field availability =?Utf-8?B?Q2hhcmxlcyBUYW0=?= Microsoft Access Form Coding 1 27th Jun 2005 07:21 AM
how to check availability pam2004 Microsoft Access 1 20th Feb 2004 06:47 AM
How to check the file availability on server Anil Microsoft C# .NET 4 24th Aug 2003 06:11 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:41 AM.