| Author |
Message |
Terry
Guest
|
Posted:
Tue Jan 11, 2005 1:19 am Post subject:
Enum existing printers then remove them. |
|
|
Hello everyone,
I am looking for some info on why I can't enumerate network printer
connections on a computer and then use the ReomovePrinterConnection method to
delete them.
I get an error that the network connection does not exist.
These printers where carelessly mapped as persistent connections prior to me
taking over the domain and now I want to get rid of them.
here is a snipit of code:
Set objNet = CreateObject("WScript.Network")
Set colOfNetPrinters = objNet.EnumPrinterConnections
On error Resume Next
For i = 0 to colOfNetPrinters.Count -1 Step 2
objNet.RemovePrinterConnection colOfNetPrinters.Item(i+1), True, True
if err.number <> 0 then
WSCript.Echo "An error occuried trying to remove printer connection " &
colOfNetPrinters.Item(i+1) & _
" The error number is " & err.number & " error description " &
err.description
err.clear
end if
Next
Thanks in advance for your help. |
|
| Back to top |
|
 |
Torgeir Bakken (MVP)
Guest
|
Posted:
Tue Jan 11, 2005 1:39 am Post subject:
Re: Enum existing printers then remove them. |
|
|
Terry wrote:
| Quote: | Hello everyone,
I am looking for some info on why I can't enumerate network printer
connections on a computer and then use the ReomovePrinterConnection method to
delete them.
I get an error that the network connection does not exist.
These printers where carelessly mapped as persistent connections prior to me
taking over the domain and now I want to get rid of them.
here is a snipit of code:
[snip]
Hi |
Does the modified script below work better?
'--------------------8<----------------------
Set objNet = CreateObject("WScript.Network")
Set colOfNetPrinters = objNet.EnumPrinterConnections
On Error Resume Next
For i = 0 to colOfNetPrinters.Count -1 Step 2
' operate only on UNC based printer connections
If Left(colOfNetPrinters.Item(i+1), 2) = "\\" Then
objNet.RemovePrinterConnection colOfNetPrinters.Item(i+1), True, True
If err.number <> 0 Then
WSCript.Echo "An error occuried trying to remove printer connection " _
& colOfNetPrinters.Item(i+1) & " The error number is " & err.number _
& " error description " & err.description
err.clear
End If
End If
Next
'--------------------8<----------------------
--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx |
|
| Back to top |
|
 |
Terry
Guest
|
Posted:
Tue Jan 11, 2005 2:11 am Post subject:
Re: Enum existing printers then remove them. |
|
|
I wish it did.
I still have the same error.
All the printers installed on the computers are network shares so it is not
choking on a local printer.
I can echo the printer names and I get the full UNC for the printers and
they are all network printer connections.
Thanks
"Torgeir Bakken (MVP)" wrote:
| Quote: | Terry wrote:
Hello everyone,
I am looking for some info on why I can't enumerate network printer
connections on a computer and then use the ReomovePrinterConnection method to
delete them.
I get an error that the network connection does not exist.
These printers where carelessly mapped as persistent connections prior to me
taking over the domain and now I want to get rid of them.
here is a snipit of code:
[snip]
Hi
Does the modified script below work better?
'--------------------8<----------------------
Set objNet = CreateObject("WScript.Network")
Set colOfNetPrinters = objNet.EnumPrinterConnections
On Error Resume Next
For i = 0 to colOfNetPrinters.Count -1 Step 2
' operate only on UNC based printer connections
If Left(colOfNetPrinters.Item(i+1), 2) = "\\" Then
objNet.RemovePrinterConnection colOfNetPrinters.Item(i+1), True, True
If err.number <> 0 Then
WSCript.Echo "An error occuried trying to remove printer connection " _
& colOfNetPrinters.Item(i+1) & " The error number is " & err.number _
& " error description " & err.description
err.clear
End If
End If
Next
'--------------------8<----------------------
--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx
|
|
|
| Back to top |
|
 |
Terry
Guest
|
Posted:
Tue Jan 11, 2005 3:27 am Post subject:
Re: Enum existing printers then remove them. |
|
|
I think I found the problem.
I started looking around at the computers and the majority of them are
running script engine 5.1. I updated a couple of computers to 5.6 and the
script is working now.
I don’t think anyone really used any scripting here,besides dos batch files.
I have a job set to go out to update the computers to 5.6 tonight.
Thanks for the help.
Terry
"Terry" wrote:
| Quote: | I wish it did.
I still have the same error.
All the printers installed on the computers are network shares so it is not
choking on a local printer.
I can echo the printer names and I get the full UNC for the printers and
they are all network printer connections.
Thanks
"Torgeir Bakken (MVP)" wrote:
Terry wrote:
Hello everyone,
I am looking for some info on why I can't enumerate network printer
connections on a computer and then use the ReomovePrinterConnection method to
delete them.
I get an error that the network connection does not exist.
These printers where carelessly mapped as persistent connections prior to me
taking over the domain and now I want to get rid of them.
here is a snipit of code:
[snip]
Hi
Does the modified script below work better?
'--------------------8<----------------------
Set objNet = CreateObject("WScript.Network")
Set colOfNetPrinters = objNet.EnumPrinterConnections
On Error Resume Next
For i = 0 to colOfNetPrinters.Count -1 Step 2
' operate only on UNC based printer connections
If Left(colOfNetPrinters.Item(i+1), 2) = "\\" Then
objNet.RemovePrinterConnection colOfNetPrinters.Item(i+1), True, True
If err.number <> 0 Then
WSCript.Echo "An error occuried trying to remove printer connection " _
& colOfNetPrinters.Item(i+1) & " The error number is " & err.number _
& " error description " & err.description
err.clear
End If
End If
Next
'--------------------8<----------------------
--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx
|
|
|
| Back to top |
|
 |
|
|
|
|