views:

438

answers:

2

Since HTA applications are hosted within MSHTA.exe how does one provide a manifest? Plus I assume providing a MSHTA.exe.manifest could potentially break other HTA apps?

A: 

Edit: My answer is wrong, but I'll leave it here to avoid any similar wrong answers :)


If you question is can you access a COM object without registering it on the machine, then I think the answer is a tentative yes. However the work you would need to do would be substantial and would mean implementing a lot of the low level code that most development tools provide for you as a matter of course (Delphi, .NET, JAVA). You would need to interface with the dll directly (like you would a normal dll ), query its interfaces and call your methods.

If you have C, C++ knowledge, the way COM is accessed from these languages would give you some pointers.

Sorry I cant be of any more help.

Toby Allen
Of course I could do old fashion "LoadLibrary"/"GetProcAddress" but this is an HTA application... I don't understand how would I make Win32 API calls from HTA?
Matt Davison
The question was regarding Registration Free COM which is a feature added to the OS. With this feature COM calls are transparent, no need for LoadLibrary, etc calls. That being said, the feature relies on associating a manifest with the client app, so I don't think you can do it from HTA.
DSO
+3  A: 

On Vista+, MSHTA.exe has an embedded manifest, which takes priority over external manifests, so your suggestion is not an option.

On XP/2003, yes, your suggestion would work, although it would be bad form, as is dropping files in System32 to modify the behavior of a system binary (especially make sure that any registration you put in the manifest are objects you are the only one to care about).

The proper solution, available on Win2003 and above, is to use the Microsoft.Windows.ActCtx object to instantiate your object given an explicit manifest reference.

For example:

var actCtx = WScript.CreateObject("Microsoft.Windows.ActCtx");
actCtx.Manifest = "myregfree.manifest";
var obj =  actCtx.CreateObject("MyObj");

Perhaps, if this must work on XP as well, a path you may take is a combination of both solutions.

Eugene Talagrand
Has anyone checked to see whether or not XP SP3 includes the ActCtx assembly? It does appear to be deployable as well according to the MSDN article linked above.
Bob
I tried this and it only works if I put my DLL in the same directory as MSHTA.exe - can I put my DLL in a different (not UAC limited) directory and point MSHTA at it with settings? Nothing I tried in the manifest file seemed to work, loadFrom attribute is ignored.
Andrew
Technically the manifest "myregfree.manifest" above is an application manifest. COM registration data should be put in an assembly manifest for the right directory to be probed. That's to say, myregfree.manifest should not have the registration data itself, it should instead have a dependency on a second manifest that has the data.
Eugene Talagrand