-3

My goal is to create a COM interface in my Windows local service, written with C++/MFC, whose methods could be called from a Windows Script Host JScript code running under a logged in interactive user account.

For instance, if I have a test.js that can be started with credentials of a logged in user, that does the following:

var Obj = new ActiveXObject("myservice.somename");
var Result = Obj.MyMethod("some data");

and then have MyMethod function processed in my service & return a value.

I know it's a general concept. At this stage I'm curious if such is possible (from a Windows security stand-point, i.e. calling system service from a user process) and if so, if there's any sample code that I can use as a basis for this?

I'm assuming that it must be some COM interface, right? But usually those go into a DLL. I've never tried to put them in a service.

Thank you!

c00000fd
  • 20,994
  • 29
  • 177
  • 400
  • 1
    I would appreciate explanation from those who want to downvote/close... – c00000fd Jun 02 '15 at 19:22
  • _"I would appreciate explanation from those who want to downvote/close."_ Here you go: _Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it._ Particularly for this part of your question: _"... if there's any sample code that I can use as a basis for this?"_ – πάντα ῥεῖ Jun 02 '15 at 19:30
  • @πάνταῥεῖ: What's so opinionated about this? Didn't I explain the problem? – c00000fd Jun 02 '15 at 19:36
  • You're asking for 3rd party examples or _gimme teh codez_ in an answer bub. That's off-topic period. – πάντα ῥεῖ Jun 02 '15 at 19:38
  • _"Where does Stackoverflow find these trolls ..."_ Well, that's pretty unjustified calling me so (and the others, that already agreed and down-/close voted your question). I'm just doing my job as encouraged here: Read "[What topics can I ask about here?](http://stackoverflow.com/help/on-topic)2 again if you're in doubts. Or ask on [Meta-SO](http://meta.stackoverflow.com/questions). I - am - not - a - troll! – πάντα ῥεῖ Jun 02 '15 at 20:04

1 Answers1

0

I'm posting it for my own future reference, in despite of the treatment I got in the comments to my original post. It would've saved me a day of search if someone pointed me to this article...

This CodeGuru article, "COM in plain C, Part 2" explains how to create a COM interface that can be called from the Windows Script Host. His IExample2 project shows how to create an in-proc DLL that hosts the COM interface that can be called from a VBScript included in the same project. Then regiexample2 and unregiexample2 projects also show how to register/unregister the COM interface. The VBScript can be easily adjusted to work with JScript in my OP.

One word of caution though, that project is intended to be used for installation on a 32-bit OS. For 64-bit OS, you will need to build and register a 64-bit version of the in-proc COM Dll. The registration part from a 32-bit process is similar to the one shown, except that one needs to include the KEY_WOW64_64KEY flag when opening/creating registry keys.

c00000fd
  • 20,994
  • 29
  • 177
  • 400