I am running Windows XP SP2 systems at multiple locations that log into a
Active Directory domain and have logon scripts launched via GP. I have VBS
scripts, that run with the logon scripts, that add/remove connections to
network printers. These scripts have been running fine up until about a
month ago when I started getting reports of an error message that comes up
after the script has finished running. WScript.exe - Application Error. The
instruction at "0x7c91103c" referenced memory at "<address>". The memory
could not be "written". The "0x7c9110c" seems to remain constant whereas the
second <address> changes.

The following is an example of a script that is receiving this error:

On Error Resume Next

Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.RemovePrinterConnection "\\BLV501\ANNEX_BLACK"
WshNetwork.RemovePrinterConnection "\\BLV501\ANNEX_COLOR"
WshNetwork.RemovePrinterConnection "\\BLV501\CENTRAL_BLACK"
WshNetwork.RemovePrinterConnection "\\BLV501\CENTRAL_COLOR"
WshNetwork.RemovePrinterConnection "\\BLV501\FRONT_DESK_FAX"
WshNetwork.RemovePrinterConnection "\\BLV501\NORTH_BLACK"
WshNetwork.RemovePrinterConnection "\\BLV501\NORTH_COLOR"
WshNetwork.RemovePrinterConnection "\\BLV501\SOUTH_COLOR"
WshNetwork.RemovePrinterConnection "\\BLV501\SOUTH_BLACK"
WshNetwork.RemovePrinterConnection "\\BLV501\STAFF_BLACK"
Set WshNetwork = CreateObject("WScript.Network")
WshNetwork.AddWindowsPrinterConnection "\\BLV501\ANNEX_BLACK"
WshNetwork.AddWindowsPrinterConnection "\\BLV501\ANNEX_COLOR"
WshNetwork.AddWindowsPrinterConnection "\\BLV501\CENTRAL_BLACK"
WshNetwork.AddWindowsPrinterConnection "\\BLV501\CENTRAL_COLOR"
WshNetwork.AddWindowsPrinterConnection "\\BLV501\FRONT_DESK_FAX"
WshNetwork.AddWindowsPrinterConnection "\\BLV501\NORTH_BLACK"
WshNetwork.AddWindowsPrinterConnection "\\BLV501\NORTH_COLOR"
WshNetwork.AddWindowsPrinterConnection "\\BLV501\SOUTH_COLOR"
WshNetwork.AddWindowsPrinterConnection "\\BLV501\SOUTH_BLACK"
WshNetwork.AddWindowsPrinterConnection "\\BLV501\STAFF_BLACK"

I have seemed to narrow the problem down to the "On Error Resume Next"
command. If I remove this from the script it will run without the error at
the end, however if the script tries to delete a printer that is not
installed on the local computer or add a printer that the user does not have
permissions for it throws an error and does not complete.

I am relatively new to scripting and most of my experience has been editing
existing scripts. Any help would be appreciated.

Thanks in advance for all your help
David

Re: WScript Application Error by Richard

Richard
Thu Jun 08 19:27:08 CDT 2006

I cannot explain the error, but perhaps this would be worth a try:
=====================
Option Explicit
Dim WshNetwork

Set WshNetwork = CreateObject("Wscript.Network")
Call RemovePrinter("\\BLV501\ANNEX_BLACK")
Call RemovePrinter("\\BLV501\ANNEX_COLOR")
...
Call AddPrinter("\\BLV501\ANNEX_BLACK")
Call AddPrinter("\\BLV501\ANNEX_COLOR")
...

Sub RemovePrinter(strPrinter)
On Error Resume Next
WshNetwork.RemovePrinterConnection strPrinter
End Sub

Sub Add Printer(strPrinter)
On Error Resume Next
WshNetwork.AddWindowsPrinterConnection strPrinter
End Sub
=======================

The object WshNetwork has global scope because it is declared outside of any
Sub, so it is available to all Subs. The "On Error Resume Next" conditions
only apply in the Subs, not in the main program. I note in your snippet that
you bound WshNetwork twice, using slightly different syntax. I don't think
that's a problem, but it's not necessary. I used "Option Explicit" and
declared all variables, just so there is no confusion, although I can't see
how not doing so would cause the problem.

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net

"Wolfcrazy" <Wolfcrazy@discussions.microsoft.com> wrote in message
news:A0472B3D-EA98-4211-9C09-3C77D21CC270@microsoft.com...
>I am running Windows XP SP2 systems at multiple locations that log into a
> Active Directory domain and have logon scripts launched via GP. I have
> VBS
> scripts, that run with the logon scripts, that add/remove connections to
> network printers. These scripts have been running fine up until about a
> month ago when I started getting reports of an error message that comes up
> after the script has finished running. WScript.exe - Application Error.
> The
> instruction at "0x7c91103c" referenced memory at "<address>". The memory
> could not be "written". The "0x7c9110c" seems to remain constant whereas
> the
> second <address> changes.
>
> The following is an example of a script that is receiving this error:
>
> On Error Resume Next
>
> Set WshNetwork = WScript.CreateObject("WScript.Network")
> WshNetwork.RemovePrinterConnection "\\BLV501\ANNEX_BLACK"
> WshNetwork.RemovePrinterConnection "\\BLV501\ANNEX_COLOR"
> WshNetwork.RemovePrinterConnection "\\BLV501\CENTRAL_BLACK"
> WshNetwork.RemovePrinterConnection "\\BLV501\CENTRAL_COLOR"
> WshNetwork.RemovePrinterConnection "\\BLV501\FRONT_DESK_FAX"
> WshNetwork.RemovePrinterConnection "\\BLV501\NORTH_BLACK"
> WshNetwork.RemovePrinterConnection "\\BLV501\NORTH_COLOR"
> WshNetwork.RemovePrinterConnection "\\BLV501\SOUTH_COLOR"
> WshNetwork.RemovePrinterConnection "\\BLV501\SOUTH_BLACK"
> WshNetwork.RemovePrinterConnection "\\BLV501\STAFF_BLACK"
> Set WshNetwork = CreateObject("WScript.Network")
> WshNetwork.AddWindowsPrinterConnection "\\BLV501\ANNEX_BLACK"
> WshNetwork.AddWindowsPrinterConnection "\\BLV501\ANNEX_COLOR"
> WshNetwork.AddWindowsPrinterConnection "\\BLV501\CENTRAL_BLACK"
> WshNetwork.AddWindowsPrinterConnection "\\BLV501\CENTRAL_COLOR"
> WshNetwork.AddWindowsPrinterConnection "\\BLV501\FRONT_DESK_FAX"
> WshNetwork.AddWindowsPrinterConnection "\\BLV501\NORTH_BLACK"
> WshNetwork.AddWindowsPrinterConnection "\\BLV501\NORTH_COLOR"
> WshNetwork.AddWindowsPrinterConnection "\\BLV501\SOUTH_COLOR"
> WshNetwork.AddWindowsPrinterConnection "\\BLV501\SOUTH_BLACK"
> WshNetwork.AddWindowsPrinterConnection "\\BLV501\STAFF_BLACK"
>
> I have seemed to narrow the problem down to the "On Error Resume Next"
> command. If I remove this from the script it will run without the error
> at
> the end, however if the script tries to delete a printer that is not
> installed on the local computer or add a printer that the user does not
> have
> permissions for it throws an error and does not complete.
>
> I am relatively new to scripting and most of my experience has been
> editing
> existing scripts. Any help would be appreciated.
>
> Thanks in advance for all your help
> David