Monday, March 13, 2017

Extend Windows Script Host via Registration-Free COM

I like JScript , I just wish I could more with it.  Well, now you can!  There is a lot to cover here so lets get started.

First, Registration-Free COM:

https://msdn.microsoft.com/en-us/library/ms973913.aspx

A technology that allows you to access COM objects, without having to register them.  This relies on there being a manifest that can locate the COM objects. Lots more to explore here.

Second, the Microsoft.Windows.ActCtx Object:

https://msdn.microsoft.com/en-us/library/windows/desktop/aa375644(v=vs.85).aspx

"object references manifests and provides a way for scripting engines to access side-by-side assemblies".  

Perfect!  All we need to do is create an Assembly, A Manifest, and then we can ingest our Assembly into WSH / JScript /VBScript / SCT files, and extend the capabilities of the scripting host.

Drawbacks?  Well, for one it requires writing an assembly and manifest to disk.  I know its not all the hotness of memory resident, but still interesting. In some cases we can get around the manifest being on disk , by setting the ManifestURL property, undocumented of course, but interesting still.  

Here is an example of extending PowerShell with our Dll



Also, you can extend say JScript with this technique as well:




Well, thats all I have for now, a quick example of extending the Script Hosts on Windows by using Registration-Free COM and the Activation Context Objects (ActCtx).

I'm sure there are questions and I'll do my best to answer them.  Things I still want to do/test.  I'd like to just embed the manifest into the assembly, so I only have to drop one file to disk.  Just need to get that done.

Thats all for today. So much goodness in Registration-Free COM ;-)







Cheers,

Casey 
@subTee



1 comment:

  1. I tried to make Registration-Free COM work but after two days efforts still not been successful. Could you help me with this. I prefer vbscript with my classic asp sites and it would be very useful to have registration free access to dlls made by Visual Studio to expand to scope of classic asp. Is it possible to use VS -created com-classes with manifest-files? Regards, Matti

    ReplyDelete