clivebuckwheat Posted January 20, 2012 Posted January 20, 2012 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"
gunsmokingman Posted January 20, 2012 Posted January 20, 2012 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 checkSet objNetwork = WScript.CreateObject("WScript.Network")Set colPrinters = objNetwork.EnumPrinterConnectionsFor 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 ifNext
clivebuckwheat Posted January 21, 2012 Author Posted January 21, 2012 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.
gunsmokingman Posted January 21, 2012 Posted January 21, 2012 Here is a VBS Script1:\ Loops Until Chk = True2:\ Every 60 Seconds Msgbox ask quit or waitSet 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 scriptChkWaitAddPrinter.vbs.txt
clivebuckwheat Posted January 24, 2012 Author Posted January 24, 2012 (edited) in the above scriptyou 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 January 24, 2012 by clivebuckwheat
gunsmokingman Posted January 24, 2012 Posted January 24, 2012 You wont need Set WshNetwork = CreateObject("WScript.Network") because I have the Network objectas Set objNetwork = WScript.CreateObject("WScript.Network") so all you need to add'-> Code Here To Add PrinterPrinterPath = "\\server01\2F18P"objNetwork .SetDefaultPrinter "\\server01\2F18P"
clivebuckwheat Posted January 26, 2012 Author Posted January 26, 2012 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.
gunsmokingman Posted January 26, 2012 Posted January 26, 2012 I would recommend leaving a way for the script to quit, you could increase the time between cycles.'-> Waits 60 Seconds If C1 = 60 Then5 min between cycles'-> Waits 300 Seconds If C1 = 300 Then10 min between cycles'-> Waits 600 Seconds If C1 = 600 Then
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now