Originally published on: Fri, 24 Apr 2009 22:31:20 +0000
Some time ago, I noticed a rise in interest from people in various online forums who wanted to be able to compile their VBScript or Javascript/Jscript Windows Script Host (WSH) source code into stand-alone executable files.
I wondered if they truly needed to have their compiled to machine-code or if they'd really just wanted to package a script in an EXE to prevent the casual user from tinkering with it.
I decided to create a utility called WSH2EXE.
My main goal with WSH2EXE was to keep from having to write the target VBScript or JavaScript code to the filesystem. I knew I would need to write some sort of stub to the filesystem to host the rest of the code with a call to eval() or Execute().
As I pondered various approaches, one emerged that I chose to test; I would try to have the host EXE set an environment variable with the full text of the script to be executed. Then, I would write out a short stub of script code that would eval()/Execute() the environment variable.
The output from this compiled code is:
Press ENTER to continue.
Running the script!
This is just a test.
Done running the script!
The test stub Javascript code that was created looks like this:
After the EXE terminated, the wsh_prog environment variable was nowhere to be found in the existing set of environment strings; it had been created only for the EXE process and all spawned processes.
Okay. The theory looked to be sound. Just to be certain, let's create another EXE that writes a VBScript stub to the filesystem and invokes the WSH interpreter on it.
The output was as follows:
Press ENTER to continue.
Running the second script!
This is just a test.
Done running the script!
The generated VBScript code looked like this:
I had the beginnings of WSH2EXE. Now that my proof-of-concept was complete, I needed to flesh out the remainder of my goals for the utility.
To be continued...
Unless otherwise noted, all code and text entries are Copyright ©2009 by James K. Lawless
Views expressed in this blog are those of the author and do not necessary reflect those of the author's employer. Views expressed in the comments are those of the responding individual.

Save to StumbleUpon
Digg it
Save to Reddit
Share on Facebook
Share on Twitter
More bookmarks
Click **here**
A JavaScript REPL for Android Devices
A Review of Kevin Mitnick's Book Ghost in the Wires
Play MP3 Files with Python on Windows
Scrolling GIF Banners with PerlMagick
BPL: Batch Programming Language Interpreter
Learning Z-80 Assembly Language on the TRS-80
Internet Protocols and Rhino JavaScript
Auto Save Images from the Clipboard
Book Review : Using Google App Engine
Changing the C64 Text Color in C
Why Some Web Sites will go Dark on Jan 18th
Book Review : Paull Allen - Idea Man
A 90's Experiment in Online Systems - The U.S. West CommunityLink Service