将对象的事件源连接到具有给定前缀的函数。
object.ConnectObject(strObject, strPrefix)
当您要同步对象的事件时,已连接的对象非常有用。创建对象后,ConnectObject 方法将该对象的输出接口连接到脚本文件。事件函数由该前缀和事件名称组成。
下面的示例演示使用 ConnectObject 方法连接WshRemote 对象的错误事件。
Dim Controller, RemoteScript
Set Controller = WScript.CreateObject("WSHController")
Set RemoteScript = Controller.CreateScript("test.js", "remoteserver")
WScript.ConnectObject
RemoteScript, "remote_"
RemoteScript.Execute
Do While RemoteScript.Status <> 2
WScript.Sleep 100
Loop
Sub remote_Error
Dim theError
Set theError = RemoteScript.Error
WScript.Echo "Error " & theError.Number & " - Line: " & theError.Line & ", Char: " & theError.Character & vbCrLf & "Description: " & theError.Description
WScript.Quit -1
End Sub
var Controller = WScript.CreateObject("WSHController");
var RemoteScript = Controller.CreateScript("test.js", "remoteserver");
WScript.ConnectObject
(RemoteScript, "remote_");
RemoteScript.Execute();
while (RemoteScript.Status != 2) {
WScript.Sleep(100);
}
function remote_Error()
{
var theError = RemoteScript.Error;
WScript.Echo("Error " + theError.Number + " - Line: " + theError.Line + ", Char: " + theError.Character + "\nDescription: " + theError.Description);
WScript.Quit(-1);
}
WScript 对象 | DisconnectObject 方法 | CreateObject 方法 | GetObject 方法