The following script has been written to disconnect all mapped Network Printers on a client computer. There are two examples. One using WMI and the other is using WSH Methods. Both are working. It's just a question of personal preference which one is chosen.
WSH Method
'Remove all Network printers but not local printers
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set Printers = WshNetwork.EnumPrinterConnections
For i = 0 to Printers.Count - 1 Step 2
If Left(ucase(Printers.Item(i+1)),2) = "\\" Then
WScript.Echo Printers.Item(i+1)
WSHNetwork.RemovePrinterConnection Printers.Item(i+1)
End IF
Next
WMI Method
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer Where Network = TRUE")
For Each objPrinter in colInstalledPrinters
'objPrinter.Delete_
Wscript.Echo objPrinter.Name
Next
Keine Kommentare:
Kommentar veröffentlichen