Discussion:
VBScript & JScript cross language execution?
(too old to reply)
JJ
2019-01-09 15:05:52 UTC
Permalink
Any 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.
JJ
2019-01-09 15:09:19 UTC
Permalink
Post by JJ
Any 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.
And I don't mean to execute the other language by executing a different file
type. e.g. run "cscript.exe thecode.js" from VBScript. But to actually call
a function provided from the other language.
Mayayana
2019-01-09 15:22:00 UTC
Permalink
"JJ" <***@vfemail.net> wrote

| And I don't mean to execute the other language by executing a different
file
| type. e.g. run "cscript.exe thecode.js" from VBScript. But to actually
call
| a function provided from the other language.

I'd be very surprised. They're two different
interpreters. If you run from within VBS it will
be interpreted as VBS and the js will error.
In fact, there are various interpreters. A browser
script interpreter won't be the same as WSH
interpreter. And built-in objects are different.
There's no wscript global object in a webpage
and no document global object in a .vbs or .js
file.

There are methods like Eval and ExecuteGlobal,
but none of those seems to have a language
parameter.

It sounds like you want a method in one that
only exists in the other. Maybe the better question
would be how to accomplish what you need?
Evertjan.
2019-01-09 18:06:51 UTC
Permalink
Post by JJ
Post by JJ
Any 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.
And I don't mean to execute the other language by executing a different
file type. e.g. run "cscript.exe thecode.js" from VBScript. But to
actually call a function provided from the other language.
This is nonsense, as text-files containing a script in VBS or JS or any
other scripting language cannot execute by themselves.

You will have to use a scripting engine, and "give" that engine the content
of such file to execute.

========

Now, most modern browsers will execute a text-file or text-stream with JS in
it, [and Microsoft's old and defunct browser will also execute VBS.]

========

Some web-servers, notably Windows-server, will execute files with JS [in an
old form, called "jscript"] or VBS in it, before sending the resulting
stream to the client browser.

The engine that will do both, and will execute functions defined in the
other language is the ASP-engine.

So here you can make a JS-function and execute it in the VBS-code as were it
a VBS-function. The extension that accepts such a file is usualy .asp, but
you can programme the server engine to accept any other extension, like
.html or .xyz3.

======

VBS and JS can be executed on a windows machine by the Cscript/Jscript-
engine, but not both at the same time.

======

A large number of other programmes can execute some version of JS.

======

[btw,
VB and VBA are related, but other languages thsn VBS
and are o.t. in this NG. JS as such is o.t. too]
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Mayayana
2019-01-09 18:22:42 UTC
Permalink
"Evertjan." <***@inter.nl.net> wrote

| [btw,
| VB and VBA are related, but other languages thsn VBS
| and are o.t. in this NG. JS as such is o.t. too]
|

A WSF is a Windows Script file. In other words,
he only asked about running js from vbs. VB never
came into it.
Evertjan.
2019-01-09 18:46:24 UTC
Permalink
Post by Mayayana
| [btw,
| VB and VBA are related, but other languages thsn VBS
| and are o.t. in this NG. JS as such is o.t. too]
|
A WSF is a Windows Script file. In other words,
he only asked about running js from vbs. VB never
came into it.
That's where "btw" is for,
and btw,
this is a usenet NG, not a helpdesk.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Mayayana
2019-01-09 20:49:17 UTC
Permalink
"Evertjan." <***@inter.nl.net> wrote

| That's where "btw" is for,
| and btw,
| this is a usenet NG, not a helpdesk.
|

Oh, goodie. Could you direct me to linens and
towels? I keep getting lost in the bath fixtures
section. :)
Evertjan.
2019-01-09 21:36:20 UTC
Permalink
Post by Mayayana
| That's where "btw" is for,
| and btw,
| this is a usenet NG, not a helpdesk.
|
Oh, goodie. Could you direct me to linens and
towels? I keep getting lost in the bath fixtures
section. :)
Well, we are here to teach you, if you stay on topic,
you think you need it, and it is not just lazyness.

A pity you don't sign.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
JJ
2019-01-10 15:56:30 UTC
Permalink
Post by Evertjan.
This is nonsense, as text-files containing a script in VBS or JS or any
other scripting language cannot execute by themselves.
You will have to use a scripting engine, and "give" that engine the content
of such file to execute.
I'm well aware of that. I'm not expecting JScript code to exist and be
runnable from within a VBS file. What I want is something like what WSF
does. i.e. each JScript and VBScript code, although they're in the same
file, they're contained in an XML element, and executed with their
respective engine. However, both can cal each other's public function, IIRC
access each other's global variables.
Roger
2019-01-14 13:18:09 UTC
Permalink
Post by JJ
Any 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
JJ
2019-01-14 22:31:03 UTC
Permalink
Post by Roger
JScript in VBScript...
Option Explicit
dim ojs
set ojs= createobject("ScriptControl")
Oh, right! I totally forgot about that control. So, thank you for refreshing
my memory. :)

Pity that it's only available in 32-bit platform. Considering that in 64-bit
OS, if the script is run from a 64-bit application, the 64-bit WSH is used;
and 32-bit module can't be loaded from a 64-bit application, or vice versa.
But this is just a minor issue which can be easily worked around.
Post by Roger
Running VBScript in JScript? Tricky, it would depend on how you are
running the JScript, you'd probably need IE.
Well, binary data handling is generally lacking in VBScript, so it's really
about VBScript issue, rather than VBScript from X cross language issue.

So far, I don't see any problem using JScript from VBScript, but there's an
issues when using VBScript from JScript.

VBScript built in functions/constants can't be accessed via CodeObject
property. They can only be accessed using Eval(), or AddCode() & Run(). e.g.

[JScode]
vbs = new ActiveXObject("scriptcontrol");
vbs.language = "vbscript";
WSH.echo("(" + vbs.codeobject.vbtab + ")"); //"(undefined)"
WSH.echo(vbs.eval('"(" & vbtab & ")"')); //"( )"
try { a = "(" + vbs.codeobject.chr(65) + ")" } catch(z) { a = "<error>" }
WSH.echo(a); //"<error>"
WSH.echo(vbs.eval('"(" & chr(65) & ")"')); //"(A)"
[/JScode]

So, does this means that VBScript (and probably VB too) built in
functions/constants are not stored in the global module, but a hidden module
which are always accessible from all modules? i.e. in a true global module,
but hidden.
Roger
2019-01-16 17:34:00 UTC
Permalink
Post by JJ
So, does this means that VBScript (and probably VB too) built in
functions/constants are not stored in the global module, but a hidden
module which are always accessible from all modules? i.e. in a true
global module, but hidden.
I don't know. I generally don't use the constants, but instead use the
actual value, when one language is writing a program to run in another.

Similarly, overloaded functions and methods can be a problem, and I
frequently mess up when trying to add comments, line continuations, etc.

Roger

Loading...