MSFN Forum: Need help modifying my default printer script please - MSFN Forum

Jump to content



Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Need help modifying my default printer script please Rate Topic: -----

#1 User is offline   clivebuckwheat 

  • Senior Member
  • PipPipPipPip
  • Group: Members
  • Posts: 538
  • Joined: 07-November 05

Posted 20 January 2012 - 08:05 AM

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"




#2 User is online   gunsmokingman 

  • MSFN Master
  • Group: Super Moderator
  • Posts: 2,020
  • Joined: 02-August 03
  • OS:none specified
  • Country: Country Flag

Posted 20 January 2012 - 12:06 PM

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



#3 User is offline   clivebuckwheat 

  • Senior Member
  • PipPipPipPip
  • Group: Members
  • Posts: 538
  • Joined: 07-November 05

Posted 20 January 2012 - 08:28 PM

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.

#4 User is online   gunsmokingman 

  • MSFN Master
  • Group: Super Moderator
  • Posts: 2,020
  • Joined: 02-August 03
  • OS:none specified
  • Country: Country Flag

Posted 21 January 2012 - 02:29 PM

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
Attached File  ChkWaitAddPrinter.vbs.txt (1.12K)
Number of downloads: 2

#5 User is offline   clivebuckwheat 

  • Senior Member
  • PipPipPipPip
  • Group: Members
  • Posts: 538
  • Joined: 07-November 05

Posted 24 January 2012 - 08:20 AM

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.

This post has been edited by clivebuckwheat: 24 January 2012 - 08:39 AM


#6 User is online   gunsmokingman 

  • MSFN Master
  • Group: Super Moderator
  • Posts: 2,020
  • Joined: 02-August 03
  • OS:none specified
  • Country: Country Flag

Posted 24 January 2012 - 12:46 PM

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"



#7 User is offline   clivebuckwheat 

  • Senior Member
  • PipPipPipPip
  • Group: Members
  • Posts: 538
  • Joined: 07-November 05

Posted 25 January 2012 - 11:44 PM

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.

#8 User is online   gunsmokingman 

  • MSFN Master
  • Group: Super Moderator
  • Posts: 2,020
  • Joined: 02-August 03
  • OS:none specified
  • Country: Country Flag

Posted 26 January 2012 - 12:56 AM

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


Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

2 User(s) are reading this topic
0 members, 2 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2011 msfn.org
Privacy Policy