Examining Errors Produced by Remotely Running Scripts

Microsoft® Windows® 2000 Scripting Guide

microsoft windows 2000 scripting guide

« Previous | Next »   

Knowing that a remotely executing script has encountered an error is important. However, once you know the error has occurred, you next need to determine the cause and correct the problem. If an error occurs in a remotely executing script, the WshRemoteError object can be accessed as a property of the WshRemote object. The WshRemoteError object includes a number of properties that describe the error that occurred and can help you troubleshoot the problem. These properties are shown in Table 3.25.

Table 3.25   Properties of the WshRemoteError Object

PropertyDescription
CharacterReturns the character position in the line where the error occurred. For example, in this simple script, the semicolon is an invalid character. Because the semicolon is the 14th character in the line, the Character property is 14:
Wscript.Echo ; 
DescriptionBrief description of the error.
LineLine number of the script in which the error occurred.
NumberError code associated with the error.
SourceIdentifies the COM object that reported the error.
SourceTextContains the line of code that generated the error. The SourceText cannot always be retrieved; in that case, an empty string will be returned.

The script in Listing 3.44 includes a subroutine that handles the Error event. Unlike the script in Listing 3.43, which simply displayed a message indicating that an error occurred, this script uses the WshRemote object Error property to retrieve an instance of the WshRemoteError object. The script then displays all of the properties of the WshRemoteError object, providing you with a great deal of information that is useful for troubleshooting the problem.

Listing 3.44   Examining Errors Produced by a Script Running Remotely

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 
strRemoteComputer = "RASServer01" strWorkerScript = "CreateTestFile.vbs" Set objWshController = WScript.CreateObject("WshController") Set objRemoteScript =_    objWshController.CreateScript(strWorkerScript, strRemoteComputer) Wscript.ConnectObject objRemoteScript, "Remote_" objRemoteScript.Execute Do While Not objRemoteScript.Status = 2    Wscript.Sleep(100) Loop Sub Remote_Error    Wscript.Echo "Error Running Remote Script."    Set objError = objRemoteScript.Error    Wscript.Echo "Character   :" & objError.Character    Wscript.Echo "Description :" & objError.Description    Wscript.Echo "Line        :" & objError.Line    Wscript.Echo "Number      :" & objError.Number    Wscript.Echo "Source      :" & objError.Source    Wscript.Echo "Source Text :" & objError.SourceText    objRemoteScript.Terminate    Wscript.Quit End Sub

send us your feedback Send us your feedback « Previous | Next »   


Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 635

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net