'VBScript
'on error resume next
Const ForReading = 1, ForWriting = 2, ForAppending = 8
MegaPrinter = 0
Set WSHNetwork = WScript.CreateObject("WScript.Network")
Set colPrinters = WSHNetwork.EnumPrinterConnections
Set fso = CreateObject("Scripting.FileSystemObject")
If colPrinters.Count > 0 then
For i = 0 To colPrinters.Count - 1 Step 2
if instr(colPrinters(i+1), "TNIKIT28") > 0 then
' msgbox colPrinters(i) & chr(9) & colPrinters(i+1)
WSHNetwork.RemovePrinterConnection colPrinters(i+1), true, true
writelog("remove printer \\TNIKIT28\CANONMF3")
end if
' if instr(colPrinters(i+1), "TNIKIT28") > 0 then
' MegaPrinter = 1
' end if
' Поиск удаляемого принтера
if instr(colPrinters(i+1), "BUH2") > 0 then
' msgbox colPrinters(i) & chr(9) & colPrinters(i+1)
WSHNetwork.RemovePrinterConnection colPrinters(i+1), true, true
WSHNetwork.AddWindowsPrinterConnection "\\IRUDEN12\FX890"
writelog("add printer \\IRUDEN12\FX890")
end if
if instr(colPrinters(i+1), "SECRETAR") > 0 then
' msgbox colPrinters(i) & chr(9) & colPrinters(i+1)
WSHNetwork.RemovePrinterConnection colPrinters(i+1), true, true
WSHNetwork.AddWindowsPrinterConnection "\\TNIKIT28\CANONMF3"
writelog("add printer \\TNIKIT28\CANONMF3")
end if
Next
if MegaPrinter = 0 then
WSHNetwork.AddWindowsPrinterConnection "\\TNIKIT28\ML1710"
writelog("add printer \\TNIKIT28\ML1710")
end if
End If
sub writelog (sLine)
Set fList = fso.OpenTextFile("s:\b2user\temp\new_prn.log", ForAppending, True)
fList.WriteLine sLine & " - " & now
fList.Close
end sub