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
Save to del.icio.us
Save to StumbleUpon
Digg it
Save to Reddit
Share on Facebook
Share on Twitter
More bookmarks
Subscribe!
Auto Save Clipboard Images Redux
Extending SpiderMonkey JavaScript on Windows
Rhino JavaScript to EXE with launch4j
Compiling Rhino JavaScript to Java
Directory Traversal in Rhino JavaScript
A Command-Line MP3 Player for Windows
Auto Save Images from the Clipboard
Java in a Windows EXE with launch4j
An Interview with Tom Zimmer: Forth System Developer
Setting Windows Console Text Colors in C
Directory Traversal in Rhino JavaScript
Screen Captures with Java and Clojure
Switching a Console Window to Full Screen or Windowed Mode
Thwarting HTTP Referer Trackbacks
Mad Schemes : Learning Lisp via SICP
JRuby as a Java Obfuscation Utility
MicroISV on a Shoestring
DadHacker
The Bottom Feeder
Writin' That Code!
The Recursive ISV
The Thomsen Blog
Prototypically Speaking
The Reinvigorated Programmer