I have the following VBS script that runs at logon and removes a shared
printer on a server. This work great but if the user was to logon again the
script would error saying printer does not exist. Can anyone help with
script so that if it gets this error it would not display error ocde on
screen and just finish? New to VBS.....

VBS Script

' RemovePrinterConnection.vbs - Windows logon script
' VBScript to - Network Printer
' ------------------------------------------------------'
Option Explicit
Dim objNetwork, strUNCPrinter
strUNCPrinter = "\\servername\HPLaserJ1022NW"

Set objNetwork = CreateObject("WScript.Network")
' Section which removes the network printer
objNetwork.RemovePrinterConnection strUNCPrinter

'WScript.Echo "Check Printers folder NO: " & strUNCPrinter
Wscript.Quit



Error Code Display on screen if you have already run this cript and its
tries again

Line 1
Char 1
Error: This Network connection does not exist
Code: 800708CA
Source: wshNetwork.RemoveNetworkDrive

Thanks

Re: VBS Logon Script Help by Tom

Tom
Tue Aug 15 12:53:05 CDT 2006

There are at least two ways to do this. The first is the more elegant,
but more complicated method - that is to sift through the
WScript.Network object's EnumPrinterConnections collection for the
presence or absence of the named printer. The other is to simply put
an 'On Error Resume Next' statement immediately before the offending
line of code and an 'On Error Goto 0' after it. This just disable the
automatic error handler for the duration of the potential problem.

Check out the WSH documentation for discussions of both approaches.

Tom Lavedas
============
http://members.cox.net/tglbatch/wsh

bramblewood wrote:
> I have the following VBS script that runs at logon and removes a shared
> printer on a server. This work great but if the user was to logon again the
> script would error saying printer does not exist. Can anyone help with
> script so that if it gets this error it would not display error ocde on
> screen and just finish? New to VBS.....
>
> VBS Script
>
> ' RemovePrinterConnection.vbs - Windows logon script
> ' VBScript to - Network Printer
> ' ------------------------------------------------------'
> Option Explicit
> Dim objNetwork, strUNCPrinter
> strUNCPrinter = "\\servername\HPLaserJ1022NW"
>
> Set objNetwork = CreateObject("WScript.Network")
> ' Section which removes the network printer
> objNetwork.RemovePrinterConnection strUNCPrinter
>
> 'WScript.Echo "Check Printers folder NO: " & strUNCPrinter
> Wscript.Quit
>
>
>
> Error Code Display on screen if you have already run this cript and its
> tries again
>
> Line 1
> Char 1
> Error: This Network connection does not exist
> Code: 800708CA
> Source: wshNetwork.RemoveNetworkDrive
>
> Thanks