MartynA MartynA - 7 months ago 11
Javascript Question

Get version description of js execution enviroment

I'm running javascript in the Windows Script Host, so there is no browser involved.

How do I identify, from within the script, which version of JavaScript its execution environment, WSH, supports? For those who aren't familiar with WSH, it takes as input a "raw" JavaScript script i.e. one with no surrounding

<script>
tags as HTML-embedded scripts would have. Afaik WSH passes the script straight to its registered javascript engine (JScript.Dll) for execution and no browser is involved at all.

googling only seems to turn up methods which presuppose that the script is executing in a browser, which is not the case for a script executed in WSH.

Answer

Take a look at some WSH built-in properties in the following example:

var fso = new ActiveXObject("Scripting.FileSystemObject");
var s = '';
s = s + 'WScript.Version = ' + WScript.Version + '\n';
s = s + 'WScript.BuildVersion = ' + WScript.BuildVersion + '\n';
s = s + 'ScriptEngineMajorVersion = ' + ScriptEngineMajorVersion() + '\n';
s = s + 'ScriptEngineMinorVersion = ' + ScriptEngineMinorVersion() + '\n';
s = s + 'ScriptEngineBuildVersion = ' + ScriptEngineBuildVersion() + '\n';
s = s + WScript.FullName + ' version = ' + fso.GetFileVersion(WScript.FullName) + '\n';
WScript.Echo(s);

The code gives output for me:

WScript.Version = 5.8
WScript.BuildVersion = 18283
ScriptEngineMajorVersion = 5
ScriptEngineMinorVersion = 8
ScriptEngineBuildVersion = 18231
C:\Windows\System32\WScript.exe version = 5.8.7601.18283

The point is you can retrieve WSH version that ways (though I have no idea about the difference in WScript.BuildVersion and ScriptEngineBuildVersion).

There are WSH versions 1.0, 2.0 (also called 5.1), 5.6, 5.7, 5.8 and 5.812 by the link. –°onsidering JScript version is the same as WSH (except JScript 5.1 is for WSH 2.0, and perhaps - I haven't found any proof - JScript 9.0 is for WSH 5.812, since JScript 9.0 introduced with IE 9 and later WSH 5.812 with Windows 10). You can find JavaScript and JScript versions correspondence by the link 1 and link 2.

Based on that I suppose the following compatibility:

WSH        JavaScript

1.0        1.0
2.0        1.4
5.5-5.8    1.5
5.812      1.8.1 (needs to be checked)
Comments