|
From: Adam R. <Ad...@Kn...> - 2003-02-08 16:32:59
|
I'm forwarding the message below in case anyone's interested in looking =
at Windows scripting. I have a tarball that accompanies Andrew's =
original message if you're interested.
Also, my management wants me to recruit more developers and/or encourage =
more downloads. Before I start randomly signing up Sourceforge =
accounts, if there's anyone you know of who might be interested, please =
let me know and I'll sign them up... you know how shy I am about =
spamming lists with "C0M3 S33 MY N3W W4R3Z, D00DZ..."
:) Adam
-----Original Message-----
From: S. Mike Dierken [mailto:mdi...@ho...]
Sent: Thu 2/6/2003 10:30 PM
Subject: Re: Windows Scripting
I think the WScript approach is beautiful. There are a lot of things you =
can
do with it. In fact, I write my 'sensors' with it & add them to a =
schedule
in Win2K. Doing a GET of some RSS, parsing the XML and POSTing the items =
is
really simple.
> I have also attached a version of the same script written in VBScript
(pubsub.vbs).
I love scripting, but VBS?... yuck.
> Ben: Think about what a JScript microserver means...? (the current
JavaScript MS assumes
> an IE context, how different would it be to assume a WSH context?)
You can probably build wrappers around the script host things like
CreateObject, alert(), etc.
But the biggest problem will be the object model - the COM interface is =
not
exposing the same one as the JScript client. Methods names might be =
similar,
but that's not the whole story.
For example, with COM you have event.Parameter("name") =3D value; but =
with
JScript you have event.name =3D value; - so much smoother... The ability =
to do
this comes when you implement IDispatchEx (or something like that...). =
The
obj.prop syntax gets translated into a
getProperty("name")/setProperty("name") method automatically - but you =
have
to implement the IDispatchEx interface. You should be able to find =
examples
on the Net - if not I have working code here somewhere.... Also, =
requiring a
KNEvent object as a parameter to publish() is different than accepting =
JS
Object - you might want to accept IDispatch and branch on the interface
type - that way you can accept JS objects as well as the =
custom/proprietary
KNEvent ;)
> I don't like VBScript, but if I have to use it I will.
Good man.
> Scripts can be used to quickly build COM objects (known as
> Windows Script Components).
I've heard of this but not done it myself.
----Original Message by Andrew:
All of us have probably long suspected that the Windows Scripting Host =
and Windows Scripting Environments might be ripe ground for building =
quick demos and/or tests--especially in combination with the WMI =
(Windows Management Instrumentation) capabilities built into Win2k.
=20
I have recently shed my phobias and learned what I needed to know about =
Windows Scripting. God I hate reading Microsoft documentation. 18,000 =
link-traversal and concept-stack-pops later, I am able to offer you the =
following example:
=20
//pubsub.js
=20
var shell=3DWScript.CreateObject("WScript.Shell");
var knms=3DWScript.CreateObject("KNMicroserver.KNMServer","knms_");
var ev=3DWScript.CreateObject("KNMicroserver.KNEvent");
=20
knms.ServerURI =3D "http://localhost/kn";
knms.Subscribe("/what/foobar");
=20
ev.Parameter("kn_payload")=3D"hi I'm here";
knms.Publish("/what/foobar",ev);
shell.PopUp("Click to exit...");
=20
function knms_OnEvent(ev){
shell.PopUp(ev.Parameter("kn_payload"));
}
=20
=20
This example requires the windows microserver, but nothing else to =
create it or run it (Windows Scripting Host is an integral part of Win2k =
and also Win98 I believe). You can just double click it to run it.
=20
I have also attached a version of the same script written in VBScript =
(pubsub.vbs). Ben: Think about what a JScript microserver means...? =
(the current JavaScript MS assumes an IE context, how different would it =
be to assume a WSH context?)
=20
You'll also find publish_processes.js, which is a JScript that publishes =
all known information about processes running on the current machine to =
the /what/processes topic on the localhost router. Note that WMI =
scripting (of which publish_processes.js is an example), seems to be a =
LOT easier in VBScript rather than JScript. I don't like VBScript, but =
if I have to use it I will. See the VBScript_vs_JScript pdf. For more =
information on WMI, check out http://msdn.microsoft.com and search for =
"WMI" and "WMI Scripting"
=20
Our PocketNOC example could be written as a script, thereby simplifying =
it considerably.
=20
There is an event-based interface for WMI as well, which I suspect will =
allow for "live" monitoring of activity rather than polling. WMI also =
allows for system control (e.g., termination of processes, etc.). One =
could build a senctl-like interface (see gif file) for windows, rather =
than UNIX, using WMI.
=20
Scripts can be used to quickly build COM objects (known as Windows =
Script Components). A loadable filter module that knew how to attach =
and call out to a named COM class would then allow for arbitrary windows =
scripts to be invoked for filtering/transformation in the router--slow, =
but scripted and familiar to windows hackers. One could also make the =
router module a script host directly, thereby avoiding slow COM =
invocations--I have an article outlining the steps.
|