Skip to main content
Ascherer17
16-Pearl
March 19, 2018
Question

Call Powershell/CMD Script From a Service

  • March 19, 2018
  • 1 reply
  • 2711 views

Does anyone know whether it's possible to call scripts located on the server from a Thingworx Service?  Are there any Javascript objects that are available to use?  I've tried creating ActiveXObjects in a service, but it says ActiveXObject is undefined.  

We are trying to figure out how to run a Powershell script from a subscription/service.  We have Thingworx 7.1 running on a Windows server.

There's not really much of a reference for the Rhino Javascript engine.  Any ideas?

1 reply

5-Regular Member
March 20, 2018

@Ascherer17 Not sure if that is possible inside TWX JS service, could you please share sample code which you are trying along with the error code you are getting.

 

-Durgesh

Ascherer17
16-Pearl
March 28, 2018

Sorry I haven't gotten back to you.  I've heard from someone else that Thingworx is purposefully given little to no access to the OS which is understandable. 

 

One set of code I've tried as a Service:

 

var oShell = new ActiveXObject("Shell.Application");
var commandtoRun = "<filepath>.ps1"; 
oShell.ShellExecute(commandtoRun,"","","open","1");

 

When I use 'Test' feature on the service I get this error:

ReferenceError: "ActiveXObject" is not defined.

I think it's just not possible to call scripts directly from a service.