This isn't complete, but hopefully it will get you started. Note: this will
only work on WinNT and Win2K - there is no support for remote scripting to
or from Win9x due to security issues. And, as the WinNT setup package still
isn't quite right, it probably won't work there, too - again, sorry about
the install problems.
First, you need to enable it - it ships disabled by default. To enable, you
need to muck about in the registry, and there are three keys you'll need to
know about:
A) HKLM\Software\Microsoft\Windows Script Host\Settings\Remote
B) HKCU\Software\Microsoft\Windows Script Host\Settings\Remote
C) HKLM\Software\Microsoft\Windows Script Host\Settings\IgnoreUserSettings
A enables remote by machine, and B by user - 1 turns it on, 0 turns it off.
If C is 1, then B is ignored and only the setting from A is read. If C is 0,
then first WSH checks B and falls back on A if B doesn't exist (we don't
create B automatically - you should create that yourself if you need to
control remoting on a user-by-user basis).
The following script shows how to use Remote WSH.
-------------------------------------
var WshController = new ActiveXObject("WSHController);
var RemoteScript =
WshController.CreateScript("c:\\localpath\\somescript.wsf",
"remotemachinename");
// Status should be 0 at this point - let's check
WScript.Echo("Current Status is " + RemoteScript.status);
// Let's catch the events
WScript.ConnectObject(RemoteScript, "RemoteScript_");
// Let's start the script
RemoteScript.Execute();
// If it's not done, the status should be 1
WScript.Echo("Current Status is " + RemoteScript.status);
// Wait for it to finish
while (RemoteScript.Status != 2)
{
WScript.Sleep(100);
Quote:
}
// Let's check the status, just for fun - should be 2
WScript.Echo("Current Status is " + RemoteScript.status);
// How about some functions to catch the events
function RemoteScript_Start()
{
WScript.Echo("The script has started on the remote machine");
Quote:
}
function RemoteScript_End()
{
WScript.Echo("The script has finished on the remote machine");
Quote:
}
function RemoteScript_Error()
{
var str = "An error has occurred\n";
var ErrorObject = RemoteScript.Error;
str += "Description: " + ErrorObject.Description + "\n";
str += "Line Number: " + ErrorObject.Line + "\n";
str += "Character: " + ErrorObject.Character + "\n";
str += "Source: " + ErrorObject.Source + "\n";
str += "Source Text: " + ErrorObject.SourceText + "\n";
str += "Number: " + ErrorObject.Number + "\n";
WScript.Echo(str);
Quote:
}
---------------------------------------------
Hope this helps. I'm not sure of the status of the docs right now, so feel
free to post any questions to the group and I'll try to answer them
promptly.
Mike Whalen
Windows Script Dev
Quote:
> While we are waiting breathlessly for the documentation. Has anybody
> got an example of the the WshRemote object?
> Michael Janos
> Sent via Deja.com http://www.deja.com/
> Before you buy.