断开已连接对象的事件源的连接。
object.DisconnectObject(obj)
对象一旦被“断开连接”,WSH 将不会响应其事件。但是该对象仍能引发事件。注意,如果指定的对象还未连接,DisconnectObject 方法将不执行任何操作。
下面的示例演示使用 DisconnectObject
方法在完成远程脚本之后断开 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
WScript.DisconnectObject
RemoteScript
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);
}
WScript.DisconnectObject
(RemoteScript)
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 对象 | ConnectObject 方法 | CreateObject 方法 | GetObject 方法