Jump to content

Recommended Posts

Posted

Here is my script, the only functionally I'd like to add is to keeping checking if the printer exists and once it is found to exist THEN set the default printer. Is this possible?. I am not very good in VBScript yet, so thanks in advance for any help you can offer.

WScript.Sleep(1000 * 60)

Set WshNetwork = CreateObject("WScript.Network")
PrinterPath = "\\server01\2F18P"
WshNetwork.SetDefaultPrinter "\\server01\2F18P"


Posted

Perhaps this Managing Network Printers Link

Here is a code sample from the link with a check for your printer,

I tested only for run time errors and there was none on my computer.

Example with check


Set objNetwork = WScript.CreateObject("WScript.Network")
Set colPrinters = objNetwork.EnumPrinterConnections
For i = 0 to colPrinters.Count -1 Step 2
If colPrinters.Item(i) = "\\server01\2F18P" Then
Wscript.Echo colPrinters.Item(i) & vbTab & colPrinters.Item (i + 1)
End if
Next

Posted

Great thanks for your reply and help, we have to wait until the printer is installed from the AD server, how would we "loop" the checking until the printer exists and THEN and only then set the default.

Posted

Here is a VBS Script

1:\ Loops Until Chk = True

2:\ Every 60 Seconds Msgbox ask quit or wait


Set objNetwork = WScript.CreateObject("WScript.Network")
Set colPrinters = objNetwork.EnumPrinterConnections
Dim C1, C2, Chk, Printer
'-> Place The Printer You Want To Check For
Printer = "hp officejet 4100 series"
'-> Loops Until True
Do Until Chk = True
C1 = C1 + 1
For i = 0 to colPrinters.Count -1 Step 2
If colPrinters.Item(i + 1) = Printer Then
'-> Code Here To Add Printer
Wscript.Echo "Adding Printer : " & colPrinters.Item(i + 1)
Chk = True
End If
Next
WScript.Sleep 1000
'-> Waits 60 Seconds
If C1 = 60 Then
C2 = C2 + 1
'-> Msgbox Ask To Quit Or Wait
If MsgBox(_
" Script Has Been Active For : " & C2 & " Minutes." & vbCrLf & vbCrLf & _
"Would you like to quit the script or wait for" & vbCrLf & _
"the printer to be added?" & vbCrLf & vbCrLf & _
"No to quit this script and not add the printer," & vbCrLf & _
"Yes to wait for the printer to be added?",4132,"Quit Or Contimue") = 7 Then
WScript.Quit
Else
'-> Yes Selected Reset Counter To Zero
C1 = 0
End If
End If
Loop

Rename ChkWaitAddPrinter.vbs.txt to ChkWaitAddPrinter.vbs to make active script

ChkWaitAddPrinter.vbs.txt

Posted (edited)

in the above script

you have code here to add printer section. I put the following below there?

Set WshNetwork = CreateObject("WScript.Network")
PrinterPath = "\\server01\2F18P"
WshNetwork.SetDefaultPrinter "\\server01\2F18P"

appreciate your help.

Edited by clivebuckwheat
Posted

You wont need Set WshNetwork = CreateObject("WScript.Network") because I have the Network object

as Set objNetwork = WScript.CreateObject("WScript.Network") so all you need to add


'-> Code Here To Add Printer
PrinterPath = "\\server01\2F18P"
objNetwork .SetDefaultPrinter "\\server01\2F18P"

Posted

thanks for your help.

I implemented the script tonight. it is not quite performing as I had hoped.

I would like the script to keeping checking for the existance of a printer, (our printers are pulled down via GPO), every login. If there is no printers there yet, i'd like the script to siliently keep checking for a specific printer and then once it finds it then set the default, I do not need the message box. It seems it doesn't keep checking silently for the existance of the printer.

Set objNetwork = WScript.CreateObject("WScript.Network")
Set colPrinters = objNetwork.EnumPrinterConnections
Dim C1, C2, Chk, Printer
'-> Place The Printer You Want To Check For
Printer = "\\printserver\2F24P"
objNetwork.SetDefaultPrinter "\\printserver\2F24P"
'-> Loops Until True
Do Until Chk = True
C1 = C1 + 1
For i = 0 to colPrinters.Count -1 Step 2
If colPrinters.Item(i + 1) = Printer Then
'-> Code Here To Add Printer
'->Wscript.Echo "Adding Printer : " & colPrinters.Item(i + 1)
Chk = True
End If
Next
WScript.Sleep 1000
'-> Waits 60 Seconds
If C1 = 60 Then
C2 = C2 + 1
'-> Msgbox Ask To Quit Or Wait
If MsgBox(_
" Script Has Been Active For : " & C2 & " Minutes." & vbCrLf & vbCrLf & _
"Would you like to quit the script or wait for" & vbCrLf & _
"the printer to be added?" & vbCrLf & vbCrLf & _
"No to quit this script and not add the printer," & vbCrLf & _
"Yes to wait for the printer to be added?",4132,"Quit Or Contimue") = 7 Then
WScript.Quit
Else
'-> Yes Selected Reset Counter To Zero
C1 = 0
End If
End If
Loop

This is what happens when the printers have not come down yet

"there is no printer called \\printserver\2F24P"

Thanks for any advice.

Posted

I would recommend leaving a way for the script to quit, you could increase the time between cycles.

'-> Waits 60 Seconds   
If C1 = 60 Then

5 min between cycles

'-> Waits 300 Seconds   
If C1 = 300 Then

10 min between cycles

'-> Waits 600 Seconds   
If C1 = 600 Then

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...