I need to write some scripts for WinXP to support some of the analysts here at Big Financial Corp. Please help me decide which type of windows scripting best fits my needs.
My needs seem pretty simple (to me anyway)
- run on WinXP Pro SP2 (version 2002)
- not require my users to install anything (so Powershell is out. Likewise Perl, Python, and other common suggestions for these types of questions on stackoverflow)
- written in a non-compiled language (so users have a chance to modify them in the future)
- reasonably complete language features (especially date/time manipulation functions. I would like to also have modern concepts like subroutines, recursion, etc)
- ability to launch and control other programs (at the commandline)
From my hurried review of my options, it looks like my choices are
- VBScript
- WScript
- JScript
I don't have time to learn or do an in-depth review of these (or whatever else a standard install of WinXP has available). I have a pretty urgent need to pick on and hack something together as quickly as possible.
(Current crisis is the need to run a given application, passing several date parameters).
Once the current crisis is over, there will be more requests like this.
Help me Obi Wan Stackoverflow... you're my only hope.
[edit] My current skill set includes Perl, Javascript, and Java so I'm most comfortable using something similar to these
[edit] ok. I'll try writing a WSH file in JScript. Thanks everyone... I'll let you know how it goes (and figure out accepting an answer) once things settle down around here a bit.
[edit] It all worked out in the end. Thanks for the quick responses folks. Here's what I gave my user
<job id="main">
<script language="JScript">
// ----- Do not change anything above this line ----- //
var template = "c:\\path\\to\\program -##PARAM## --start ##date1## --end ##date2## --output F:\\path\\to\\whereever\\ouput_file_##date1##.mdb";
// Handle dates
// first, figure out what they should be
dt = new Date();
var date1 = stringFromDate(dt, 1);
var date2 = stringFromDate(dt, 2);
// then insert them into the template
template = template.replace(new RegExp("##date1##", "g"), date1);
template = template.replace(new RegExp("##date2##", "g"), date2);
// This application needs to run twice, the only difference is a single parameter
var params = ["r", "i"]; // here are the params.
// set up a shell object to run the command for us
var shellObj = new ActiveXObject("WScript.Shell");
// now run the program once for each of the above parameters
for ( var index in params )
{
var runString = template; // set up the string we'll pass to the wondows console
runString = runString.replace(new RegExp("##PARAM##", "g"), params[index]); // replace the parameter
WScript.Echo(runString);
var execObj = shellObj.Exec( runString );
while( execObj.Status == 0 )
{
WScript.Sleep(1000); //time in milliseconds
}
WScript.Echo("Finished with status: " + execObj.Status + "\n");
}
// ----- supporting functions ----- //
// Given a date, return a string of that date in the format yyyy-m-d
// If given an offset, it first adjusts the date by that number of days
function stringFromDate(dateObj, offsetDays){
if (typeof(offsetDays) == "undefined"){
offsetDays = 0;
}
dateObj.setDate( dateObj.getDate() + offsetDays );
var s = dateObj.getYear() + "-"; //Year
s += (dateObj.getMonth() + 1) + "-"; //Month (zero-based)
s += dateObj.getDate(); //Day
return(s);
}
// ----- Do not change anything below this line ----- //
</script>
</job>
Clearly it could be better... but it got the job done and is easy enough for my user to understand and extend himself.