I have written a script in an attempt to remove all printers for the current user logged onto a windows workstation and I am getting a "Network connection does not exist" error. However, the connection is there. The code is as follows:
On Error Resume Next
Dim wshNetwork, oPrinters, Count
Set wshNetwork = CreateObject("WScript.Network"
Set oPrinters = wshNetwork.EnumPrinterConnections
Count = oPrinters.Count
Do While Count <> 0
wshNetwork.RemovePrinterConnection oPrinters.Item(Count-1), True, True
If Err.Number <> 0 Then
WScript.Echo Err.Description
Else
WScript.Echo oPrinters.Item(Count-1) & " Removed"
End If
Count = Count -1
Loop
oPrinters.Item(Count-1) returns the following:
even numbers - "FPR4:" (port)
odd numbers - "\\ServerName\PrinterName" (printer)
-all returned values are valid
Error: Network Connection Does Not Exist
How can a network connection not exist when it was just found using the wshNetwork.EnumPrinterConnections(Item) property?
On Error Resume Next
Dim wshNetwork, oPrinters, Count
Set wshNetwork = CreateObject("WScript.Network"
Set oPrinters = wshNetwork.EnumPrinterConnections
Count = oPrinters.Count
Do While Count <> 0
wshNetwork.RemovePrinterConnection oPrinters.Item(Count-1), True, True
If Err.Number <> 0 Then
WScript.Echo Err.Description
Else
WScript.Echo oPrinters.Item(Count-1) & " Removed"
End If
Count = Count -1
Loop
oPrinters.Item(Count-1) returns the following:
even numbers - "FPR4:" (port)
odd numbers - "\\ServerName\PrinterName" (printer)
-all returned values are valid
Error: Network Connection Does Not Exist
How can a network connection not exist when it was just found using the wshNetwork.EnumPrinterConnections(Item) property?