From: James on
I have a simple script to remove some old printer objects from client
machines. They all reference an old printer server that's been
decommissioned. For client machines that don't have these printer
objects the script throws an error. What kind of condition can I put in
the script so the 'WshNetwork.RemovePrinterConnection' command doesn't
run if the listed printers are not on the client machine?

Set WshNetwork = CreateObject("WScript.Network")
WshNetwork.RemovePrinterConnection "\\old_prntsrvr.domain.local\printer1
WshNetwork.RemovePrinterConnection "\\old_prntsrvr.domain.local\printer2
' WScript.quit

Thanks,
From: Francois Lafont on
Le 19/09/2010 08:35, James a �crit :

> I have a simple script to remove some old printer objects from client
> machines. They all reference an old printer server that's been
> decommissioned. For client machines that don't have these printer
> objects the script throws an error. What kind of condition can I put in
> the script so the 'WshNetwork.RemovePrinterConnection' command doesn't
> run if the listed printers are not on the client machine?


I asked myself the same question and I had built the
"connecte_imprimantes()" (sorry it's in French) function like this :



a)
my_list = "\\SRV\S2-EPSON1|\\SRV\S2-EPSON2"
Call connecte_imprimantes(my_list)

disconnects printers which aren't in the "my_list" list (and which are
already connected with the PC), connects the printers which are in
"my_list" list (and which aren't already connected with the PC) and sets
the first printer in "my_list" list as the default printer.

b)
Call connecte_imprimantes("")

removes all printers which are already connected.




I had tested this function few times (with Windows XP), but it seemed to
work well. Hope this help :
http://sisco.laf.free.fr/codes/connexionsImprimantes2.html


--
Fran�ois LAFONT
From: Todd Vargo on
James wrote:
>I have a simple script to remove some old printer objects from client
> machines. They all reference an old printer server that's been
> decommissioned. For client machines that don't have these printer
> objects the script throws an error. What kind of condition can I put in
> the script so the 'WshNetwork.RemovePrinterConnection' command doesn't
> run if the listed printers are not on the client machine?
>
> Set WshNetwork = CreateObject("WScript.Network")
> WshNetwork.RemovePrinterConnection "\\old_prntsrvr.domain.local\printer1
> WshNetwork.RemovePrinterConnection "\\old_prntsrvr.domain.local\printer2
> ' WScript.quit

This is a case where On Error Resume Next is appropriate.

--
Todd Vargo

(Post questions to group only. Remove "z" to email personal messages)
From: Al Dunbar on


"Todd Vargo" <tlvargo(a)sbcglobal.netz> wrote in message
news:#nsNnU$VLHA.6132(a)TK2MSFTNGP05.phx.gbl...
> James wrote:
>>I have a simple script to remove some old printer objects from client
>>machines. They all reference an old printer server that's been
>>decommissioned. For client machines that don't have these printer objects
>>the script throws an error. What kind of condition can I put in the
>>script so the 'WshNetwork.RemovePrinterConnection' command doesn't run if
>>the listed printers are not on the client machine?
>>
>> Set WshNetwork = CreateObject("WScript.Network")
>> WshNetwork.RemovePrinterConnection "\\old_prntsrvr.domain.local\printer1
>> WshNetwork.RemovePrinterConnection "\\old_prntsrvr.domain.local\printer2
>> ' WScript.quit
>
> This is a case where On Error Resume Next is appropriate.

And the simplest.

/Al


From: James on
On 9/19/2010 5:21 AM, Todd Vargo wrote:
> James wrote:
>> I have a simple script to remove some old printer objects from client
>> machines. They all reference an old printer server that's been
>> decommissioned. For client machines that don't have these printer
>> objects the script throws an error. What kind of condition can I put
>> in the script so the 'WshNetwork.RemovePrinterConnection' command
>> doesn't run if the listed printers are not on the client machine?
>>
>> Set WshNetwork = CreateObject("WScript.Network")
>> WshNetwork.RemovePrinterConnection "\\old_prntsrvr.domain.local\printer1
>> WshNetwork.RemovePrinterConnection "\\old_prntsrvr.domain.local\printer2
>> ' WScript.quit
>
> This is a case where On Error Resume Next is appropriate.
>
Thanks, I used this at the beginning of the script.
 | 
Pages: 1
Prev: Help with writing a script
Next: sftp and vbs