fowlerontherun
Programmer
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
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