Post by JJAny way or trick to execute JScript code from VBScript code in a VBS
file, or execute VBScript code from JScript code in a JS file?
FYI, I already know about VBScript & JScript cross language execution
via HTML, HTA, and WSF files. I want to know if it's also possible from
a VBS or JS file.
JScript in VBScript...
Option Explicit
dim ojs
set ojs= createobject("ScriptControl")
ojs.language = "JScript"
ojs.AddCode "function x(a,b) {return 'answer = ' +(a+b);}"
msgbox(ojs.Run("x",1,2))
You might need to register the control (32 bit)
%windir%\SysWoW64\regsvr32.exe %windir%\SysWoW64\msscript.ocx
And you'll need to run it as 32 bit
%windir%\SysWoW64\cscript.exe whatever.vbs
Running VBScript in JScript? Tricky, it would depend on how you are
running the JScript, you'd probably need IE.
I've used the above method to run VBScript in other programming languages.
For instance, VFP6 calls VBScript, which then uses .Net to create a SHA256
hash.
objvb.language = "VBScript"
(The following needs to be on one line)
objvb.addcode('function fnh(x,y):
dim e,c,h:set e=createobject("System.Text.UTF8Encoding"):
set c=createobject("System.Security.Cryptography.HMACSHA256"):
c.Key=e.GetBytes_4(x):
h=c.ComputeHash_2(e.GetBytes_4(y)):
fnh=h:
end function ')
Called with...
hash = objvb.run("fnh", key, text)
Similarly VFP6 has trouble with binary streams downloaded from the
internet, but VBScript can download and save the file, without VFP6 ever
being aware.
objvb.addcode('function fnk(ohttp,f):
dim e:
set e=CreateObject("ADODB.Stream"):
e.type=1:
e.open:
e.write ohttp.ResponseBody:
e.savetofile f, 2:
set e = nothing:
end function ')
Called with...
objvb.run("fnk", httpobject, filename)
Roger