Why is WSCript object not known to my script that's controlled by a custom IScriptControl?

StackOverflow https://stackoverflow.com/questions/4180598

  •  10-10-2019
  •  | 
  •  

Question

I am using someone else's library that provides its own scripting host instance, it appears.

This lib provides me with functions to define the type of scripting language such as "jscript" and "vbscript", and I can supply it with script code and have that executed, with passing arguments in and back. So, basically, it works.

However, when I try to access the "WScript" object, I get an exception saying that this keyword is undefined.

The developer, not knowing much about this either (he only made this lib for me because I do not want to deal with Windows SDKs right now), told me that he is using "IScriptControl" for this.

Oh, and the lib also provides flags to allow "only safe subset" and "allow UI", which I set to false and true, respectively.

Does that ring a bell with anyone? Do a user of IScriptControl have to take extra steps in order to make a WScript object available? Or, can he use IScriptControl in a way that this is supplied automatically, just as when running the same script from wscript.exe?

Basically, all I need is the WScript.CreateObject function in order to access another app's API via COM.

Was it helpful?

Solution

I don't know why WScript is not known, but I suspect it is because the script host doesn't provide it. Maybe only wscript.exe does this.

If you are using Javascript, to create an object you can use new ActiveXObject(). If you are using VBScript, you can just use CreateObject.

See this article for some background.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top