How to make sure that a script is run using cscript
01/22/09
How to make sure that a script is run using cscript
Most of the scripts I write are intended to be called from the command window using cscript.exe. Something like.....( the nologo argument gets rid of the title block that cscript spits outs everytime it runs )
C:\scripts>cscript /nologo someScript.vbs
Recently I ran into a situation where a script was being called using wscript.exe instead and the script was not acting properly. After a little research, I came up with this solution:
You need to figure out which interpreter is being used. You do this by looking at the fullname property of the wscript object.
'==========================================================
'== declare the local variables to be used
'==========================================================
dim scriptHost, tmpArr'==========================================================
'== get the name of the interpreter being used to run the
'== script - have to parse it out of the full path that is
'== stored in the fullname property
'==========================================================
scriptHost = wscript.fullname
tmpArr = split( scriptHost, "\" )
scriptHost = tmpArr( ubound(tmpArr) )if lcase( scriptHost ) <> "cscript.exe" then
wscript.echo "This script must be executed using cscript.exe"
wscript.quit
end if
I hope this post helped out. If it didn't, I am always looking for new scripts to add so submit a request for your question or need and I will see if I can answer it.
Dave
Pingbacks:
No Pingbacks for this post yet...
This post has 11 feedbacks awaiting moderation...
Scripts
This is somewhere I can post interesting snippets as I come across them. Hopefully some folks out there will find this helpful.
Search
Follow Me:
Categories
- All
- Web Technologies (2)
- PHP (1)
- Windows Scripting (37)
- Batch Scripts (13)
- Wsh Scripts (23)
Archives
- December 2009 (2)
- March 2009 (2)
- February 2009 (3)
- January 2009 (2)
- December 2008 (4)
- November 2008 (1)
- October 2008 (1)
- February 2008 (1)
- December 2007 (3)
- July 2007 (1)
- April 2007 (1)
- February 2007 (2)
- More...
Misc
Who's Online?
- Guest Users: 2




