Search code examples
javascriptjscriptwshactivexobject

JScript - How to know if the script was activated using WSH or internally by another script?


So I have a simple JScript file, AKA MyScript.py, that may be activated using two ways:

Using WSH (Windows Script Host)

essentially double click the file.

Internally by other script

AKA main.js

var strScript = ""; // read MyScript.js file to string
F = new Function(strScript)
(F)();

Question

Is there a way to know, in MyScript.py, how it was activated?

Note

I'm looking for some solution similar to what's implemented in Python

if __name__ == "__main__":


Solution

  • It's not as portable as the Python method, but you could check the WScript.ScriptName property. When MyScript.js is launched directly, ScriptName will return "MyScript.js". When it is included from main.js, the property will return "main.js".