ConnectObject メソッド
所定のプリフィックスを持つ関数にオブジェクトのイベント ソースを接続します。
object.ConnectObject(strObject, strPrefix)
引数
- object
WScript オブジェクトです。 - strObject
接続するオブジェクトの名前です。 - strPrefix
イベント処理関数のプリフィックスです。
解説
対象のオブジェクトには、そのクラスのイベントを列挙する機能が必要です。ConnectObject メソッドは、オブジェクト作成後にオブジェクトの出力インターフェイスをスクリプト ファイルに接続します。イベント処理関数は、このプリフィックスとイベント名を組み合わせた名前になります。
使用例
次のコードは ConnectObject メソッドを使用してWshRemote オブジェクトのエラーイベントに接続する例です。
VBScript
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
JScript
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 メソッド