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

lookup printer and remove and re-add printer

Status
Not open for further replies.

fowlerontherun

Programmer
Nov 2, 2012
5
GB
hi guys,

ive written a script used for driver changes or for when we move printers to different print servers. Ive tested it and it works fine. I wish to make one amendment and thats to make teh printer default once added.

any ideas

test1

Sub subRemovePrinters(strServer)

Dim strPrinters

strServer = "\\" & strServer
strPrinters = ""

If strServer = "\\" Then WScript.Quit

Set WshNetwork = WScript.CreateObject("WScript.Network")
Set Printers = WshNetwork.EnumPrinterConnections
For each printer in printers
If InStr(LCase(printer),LCase(strServer)) Then
strPrinters = strPrinters & printer & vbNewLine
WshNetwork.RemovePrinterConnection printer, true, true
End If
Next

'If strPrinters <> "" Then WScript.echo "*--PRINTERS--*" & vbNewLine & strPrinters & "*--REMOVED--*"

End Sub


Sub subMapPrinter(strPrintPath, strDefault)

Dim objNet
Set objNet = CreateObject("WScript.Network")

objNet.AddWindowsPrinterConnection strPrintPath

If strDefault = "DEF" Then objNet.SetDefaultPrinter strPrintPath

Set objNet = Nothing

End Sub

sub test1

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objPrinters = objWMIService.ExecQuery("Select * from Win32_Printer")

For Each objPrinter in objPrinters

msgbox(objprinter.name)

IF objprinter.name = "\\croydon-ps01\Parabis HA 7500 - 2" THEN
msgbox("found")
objPrinter.Delete_
subMapPrinter "\\croydon-ps01\Parabis HA 7500 - 2",""

end if

next


end sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top