Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 295 Vote(s) - 3.53 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Ways to communicate between JScript and Windows service

#1
I have a Windows local service that may spawn off a process to execute a JScript script (in a .js file) via the Windows Script Host. The issue is that I need to notify my service of the results generated by the script in the .js file. A transfer or a simple 32-bit integer, or a string would suffice. What would be the way to do this?

PS. The code must run on Windows XP SP3 or later OS.
Reply

#2
Your best bet is to create an out of process COM object that executes within your service. Just implement the necessary scripting interfaces and provide a member function to match the notification and call it from your script as such:

newObj = new ActiveXObject("localserver.mynotify");
newObj.Notify("finished");
Reply

#3
Would the exit code of the process be enough?

Windows Scripting host has has a [`.Quit(errorCode)`](

[To see links please register here]

) method that allows you to set the exit code.
You should be able to call WSH directly from the service and get the return code with `GetProcessExitCode()` by passing the process handle that you received after spawning it.

Note that almost everything you can do from a JScript file can also be done with native code.
Reply

#4
Do you have to execute the .js file as an external process? Windows Scripting has COM objects that an app can use to run scripts within its own process. I use this to execute script files within my service processes, and it works fine. The hosting process can even implement its own `IDispatch`-based classes and pass them to the scripting engine to expose to scripts as global objects so the scripts can communicate with the hosting process without having to use `new ActiveXObject` or `CreateObject()` to access those objects.
Reply

#5
I see your script is written in JScript and your app in C++.

Perhaps the easiest way to accomplish what you want is by writing a file, say, to programdata folder which your service should have access to. Maybe use a GUID for the particular request, pass that to the JScript so it's guaranteed to be a unique file. Not ideal.

Another way to get JScript output ... Can you call out to managed code (C#)? If so, you could use a .NET-based or .NET-callable JavaScript compiler/interpreter. This would allow you to avoid IActiveScript and also to grab the values right out of the script context or from function return. I've used [Jurassic][1] and [JavaScriptDotNet][2], both very easy to use and extend.

This might open a problem if you heavily rely on ActiveXObject calls (ie: FileSystemObject) and don't want to write components. [JuraScript][3] wraps the Jurassic engine and add ActiveXObject support to it for COM automation.

I am a C++ newb, so I don't know how much of a leap this is for you although I know it's possible to interop between managed/C++.

Just thought I'd mention these scenarios as I didn't see them listed in answers.

[1]:

[To see links please register here]

"Jurassic"
[2]:

[To see links please register here]

"JavaScriptDotNet"
[3]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through