rssval.jsb Microsoft (R) Windows Script Host Version 5.6 Copyright (C) Microsoft Corporation 1996-2001. All rights reserved. Input Error: There is no script engine for file extension ".jsb". I even tried using the //E:cscript option mentioned here, but I still get an error: CScript Error: Can't find script engine "cscript" for script "C:\njt\swtech\thea rchitect\data\rss-spec\rssval.jsb". I can't seem to concoct a set of command line arguments to run a script file of this new extension, regardless of whether or not I have registered the file type. Anyone got any suggestions? In any case, what I _really_ want to happen is for a javascript file to run in batch more when run from a command shell, and in GUI mode if run from the Windows Explorer. Maybe it's just going to be easier to remember to list the script engine explicitly on the command line: cscript.exe rssval.js ' />

May 10, 2003

Running JavaScript Batch Files on Windows

Windows now has some pretty good scripting facilities built in, and I have started using these more extensively recently. Using some simple code, it is possible to do some complex system admin tasks fairly easily. It can even run scripts remotely, which can be very useful for a sysadmin.

One thing that I wanted to do though was always run a certain script in command line "batch mode" rather than using a GUI. The Windows JavaScript engine does different things when displaying messages depending on whether it is running in the command-line engine (CScript.exe) or the GUI engine (WScript.exe), and I always wanted to see the output in the console window rather than in a pop-up dialog.

What I want to be able to do is have a file containing JavaScript code which will always execute using CScript.exe - ie always run in batch mode when started from a command shell.

My first thought was to register a new file extension and link it with the CScript.exe program, so I entered the following commands in a Windows CMD window:

ASSOC .jsb=JSBatchFile
FTYPE JSBatchFile=C:\WIN2000\System32\CScript.exe "%1" %*

This produced the following setup which seemed to be what I wanted, compared to the original .js settings.

That doesn't seem to be enough though - I get the following message when I use this new file type:

C:\>rssval.jsb
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

Input Error: There is no script engine for file extension ".jsb".

I even tried using the //E:cscript option mentioned here, but I still get an error:
CScript Error: Can't find script engine "cscript" for script "C:\njt\swtech\thea rchitect\data\rss-spec\rssval.jsb".
I can't seem to concoct a set of command line arguments to run a script file of this new extension, regardless of whether or not I have registered the file type.

Anyone got any suggestions?

In any case, what I _really_ want to happen is for a javascript file to run in batch more when run from a command shell, and in GUI mode if run from the Windows Explorer.

Maybe it's just going to be easier to remember to list the script engine explicitly on the command line:

cscript.exe rssval.js
Entry categories: Microsoft Programming
Posted by Jorgen Thelin at May 10, 2003 08:05 AM - [PermaLink]
 
Traceback List
Comments
Did you ever find a way to do this? I'm looking for a way to run a batch file (.bat) from a hyperlink, and I'm having the same problem. Aloha, --TIM. Posted by: Tim on July 16, 2003 07:19 PM
Cscript doesn't have a lot to it. With only very minor changes, it just runs the script as explorer does. Explore (and most all windows apps) executes any program/file by using entries in the HKEY_Class_Root sub tree of the registry (HKCR). Explorer: First looks up the file's extension as a key, File.doc -> HKCR\.doc It then reads the Default Value [I'll use msword as an example] HKCR\.doc(Default)="Word.Document.8" Then it looks up that value as a key "Word.Document.8" -> HKCR\Word.Document.8 And enumerates to "shell" key and reads the default HKCR\Word.Document.8\shell(Default)="OPEN" Then it looks up the value in "shell" as a key "OPEN" -> HKCR\"Word.Document.8\shell\OPEN And enumerates to "command" key and reads the default HKCR\"Word.Document.8\shell\OPEN\command(Default) = "C:\Program Files\Microsoft Office\Office\WINWORD.EXE" /n It runs this value as a command with the original filename as an argument ----------------------- Cscript works very similar: First looks up the file's extension as a key, File.mcr -> HKCR\.mcr It then reads the Default Value HKCR\.mcr(Default)="McrScriptFile" Then it looks up that value as a key "McrScriptFile" -> HKCR\McrScriptFile And enumerates to "ScriptEngine" key and reads the default HKCR\McrScriptFile\ScriptEngine(Default)="MyScriptLang" Agian it looks up that value as a key "MyScriptLang" -> HKCR\MyScriptLang Now you have an option of several keys HKCR\MyScriptLang\CLSID HKCR\MyScriptLang\CurVer HKCR\MyScriptLang\protocol\StdFileEditing If HKCR\MyScriptLang\CLSID exists It then reads the Default Value HKCR\.mcr(Default)="{12313-123123-1231231312-23123-213}" or HKCR\.mcr(Default)="Yetanotherkey" if that value is a CLSID ({lots of numbers}), meaning a link to a registered program It runs the program Other wise it will Again it looks up that value as a key "Yetanotherkey" -> HKCR\Yetanotherkey and treats this the same as "MyScriptLang" This will recurse as many levels as you wish to go If HKCR\MyScriptLang\CLSID does not exist and if HKCR\MyScriptLang\CurVer exists It will treat CurVer the same as CLSID If HKCR\MyScriptLang\CLSID does not exist and if HKCR\MyScriptLang\CurVer does not exist It will use the default value of HKCR\MyScriptLang\protocol\StdFileEditing And try to automatically register and set it up as a program (creating a CLSID key and value) This is a big mess and well past my expertise, So I recommend staying away from it. -------------------------------------------------------- Registering your own script engines (programs) is a whole different ball of wax. An easy application of this is registering new extensions for existing (registered) script engines. Add your new extension as a key HKCR\.new Set the default to a descriptive extension name HKCR\.new(Default)="NewFile" Create descriptive key HKCR\NewFile Create "ScriptEngine" key (must be "ScriptEngine") HKCR\NewFile\ScriptEngine Set the default to your virtual engine name HKCR\NewFile\ScriptEngine(Default)="NewScript" Create your virtual engine key HKCR\NewScript Create "CLSID" key (must be "CLSID" or "CurVer") HKCR\NewScript\CLSID Set its default to the name of the engine that you want to use HKCR\NewScript\CLSID(default)="VBSCRIPT" This is the real name for "MyScriptLang" key if you follow .vbs as in the above description for Cscript Now .new files will run through Cscript just as they did when named .vbs If you want to be able to double click in explorer on a .new as you did with .vbs just duplicate the "shell" key, "shell(default) value, and subkey from .vbs at the "Newfile" level to .new at the "NewFile" level. To make the right click menu the same copy all "newfile\shell" subkeys for .vbs to .new Why do all this.... Well we use VBscripting in our new Active Directory Domain. But To stop the thousands .vbs viruses we had made the HLCR\.vbs(default)="NORUN". This stops all .vbs programs (we didn't have any). But with the new need for .vbs scripts we had to reactivate it, and thus allow in viruses too. Instead we made up an extension as described above, and kept .vbs broken. All of our vbs scripts have the new extension and work great, and .vbs virus still can't execute. Hope this helps Matt Heyse West Engineering Computer Support Michigan Technological University Posted by: Matt Heyse on July 29, 2003 05:14 AM