Export (0) Print
Expand All

Examining Errors Produced by Remotely Running Scripts

Microsoft® Windows® 2000 Scripting Guide

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

Property

Description

Character

Returns 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 ;

Description

Brief description of the error.

Line

Line number of the script in which the error occurred.

Number

Error code associated with the error.

Source

Identifies the COM object that reported the error.

SourceText

Contains 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

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft