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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printers in VBScript

Status
Not open for further replies.

gazzanewpy

Instructor
Oct 21, 2002
127
GB
I am now looking at swapping all batch files for vbscript ones. I am very familiar with VB and have worked a little with VBScript but this should be treated as completely new.

I have a batch file using con2prt. It first removes all network printers from a computer (to stop any risk of the roaming profiles carrying a printer attachment around). It then adds the printers for that room onto that workstation during the time of the uer's login.

I know I can use the net.addwindowsprinterconnection and the net.setdefaultprinter. Yet, the RemovePrinterConnection requires the UNC whilst con2prt can have a global element (con2prt /f removes all network printers). I want to remove all network printers (not local) and then attach the required printers, setting one as default.

Any advice on removing the printers?
 
Try something like this:
Code:
Set Nw=CreateObject("WScript.Network")
Set oP=Nw.EnumPrinterConnections
C=oP.Count
On Error Resume Next
Do While C>0
  Nw.RemovePrinterConnection oP.Item(C-1),True,True
  If Err.Number<>0 Then
    WScript.Echo Err.Description
  Else
    WScript.Echo oP.Item(C-1) & &quot; Removed&quot;
  End If
  C=C-2
Loop

Hope This Help
PH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top