Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is Printer online?

Status
Not open for further replies.

DevelopV

Technical User
Mar 16, 2012
113
ZA
I am looking for code that will return the status of a printer.
I need to know if the printer is turned on and is online so that I can print a report to it.
The printer is NOT the default printer.

Thanks in advance


 
You need to get the list of available printers, check if the one you want is there and if so set it as default, then run your report.

You might want to store the name of the current default printer and set it back once you have finished, if you want to be nice to your users ;-)

Code:
'Declare vars
Dim WshNetwork As Object
Dim i As Integer
Dim sMyDesiredPrinter As String

' Set desired printer name
sMyDesiredPrinter = "MyPrinterName"

' Create network object
Set WshNetwork = CreateObject("WScript.Network")

' Loop printers
For i = 0 To WshNetwork.EnumPrinterConnections.Count - 1 Step 2
    
   ' If desired printer found, set to default
    If WshNetwork.EnumPrinterConnections.Item(i + 1) = sMyDesiredPrinter Then
        Call WshNetwork.SetDefaultPrinter(sMyDesiredPrinter)
    End If
Next

Set WshNetwork = Nothing

This should give you all you need to achieve your goal.

Regards,
1DMF

"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Electronic Dance Music
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top