Discussion:
Can cscript.exe be made to use a path to locate sctripts?
(too old to reply)
John H.
2010-02-18 18:48:57 UTC
Permalink
Hi,

Honestly, I’ve tried to find this on my own. I’m new to Windows
scripting. I feel like I’m missing some really basic concept. Is it
possible to have cscript.exe search the PATH (or other directory list)
to find a .vbs file to execute? I have a series of .vbs scripts
stored is a set of network directories with long path names. I’d like
to be able to execute these scripts by just entering “cscript.exe
scriptname.vbs” from the command line w/o specifying full path to
the .vbs file each time.

I’ve added the script directories to my PATH. My PATHEXT
environmental variable has .vbs in the list.

Thanks,
John
Pegasus [MVP]
2010-02-18 19:07:18 UTC
Permalink
Post by John H.
Hi,
Honestly, I’ve tried to find this on my own. I’m new to Windows
scripting. I feel like I’m missing some really basic concept. Is it
possible to have cscript.exe search the PATH (or other directory list)
to find a .vbs file to execute? I have a series of .vbs scripts
stored is a set of network directories with long path names. I’d like
to be able to execute these scripts by just entering “cscript.exe
scriptname.vbs” from the command line w/o specifying full path to
the .vbs file each time.
I’ve added the script directories to my PATH. My PATHEXT
environmental variable has .vbs in the list.
Thanks,
John
You can do it the other way round: If you just enter "scriptname.vbs" then
the Command Processor will find it for you.
John H.
2010-02-18 19:23:09 UTC
Permalink
Okay, I got that to work. Thanks. The scripts that I want to run
require cscript.exe as a script host. Since the default script host
is wscript.exe I was getting an error when I ran the .vbs file
directly from the command line. So I ran cscript.exe /H:cscript to
change the default. Now I can just run the .vbs file from the command
line. Very cool!

Is there a down side to changing my default script host to cscript.exe
that might trip me up later?

Thanks,
John
Pegasus [MVP]
2010-02-18 19:38:05 UTC
Permalink
Post by John H.
Okay, I got that to work. Thanks. The scripts that I want to run
require cscript.exe as a script host. Since the default script host
is wscript.exe I was getting an error when I ran the .vbs file
directly from the command line. So I ran cscript.exe /H:cscript to
change the default. Now I can just run the .vbs file from the command
line. Very cool!
Is there a down side to changing my default script host to cscript.exe
that might trip me up later?
Thanks,
John
None that I'm aware of.
Tom Lavedas
2010-02-18 21:23:24 UTC
Permalink
Post by Pegasus [MVP]
Okay, I got that to work.  Thanks.  The scripts that I want to run
require cscript.exe as a script host.  Since the default script host
is wscript.exe I was getting an error when I ran the .vbs file
directly from the command line.  So I ran cscript.exe /H:cscript to
change the default.  Now I can just run the .vbs file from the command
line.  Very cool!
Is there a down side to changing my default script host to cscript.exe
that might trip me up later?
Thanks,
John
None that I'm aware of.
Maybe a tiny one, if the OP dislikes command console windows popping
up anywhere as much as I do. Of course, this only happens when a
procedure is launched by dropping a file onto it or a shortcut that
points to it. Or when it is run by double-clicking in explorer.
Other than that, there's probably no other downside.
_____________________
Tom Lavedas
Al Dunbar
2010-02-19 05:54:45 UTC
Permalink
Post by Tom Lavedas
Post by Pegasus [MVP]
Post by John H.
Okay, I got that to work. Thanks. The scripts that I want to run
require cscript.exe as a script host. Since the default script host
is wscript.exe I was getting an error when I ran the .vbs file
directly from the command line. So I ran cscript.exe /H:cscript to
change the default. Now I can just run the .vbs file from the command
line. Very cool!
Is there a down side to changing my default script host to cscript.exe
that might trip me up later?
Thanks,
John
None that I'm aware of.
Maybe a tiny one, if the OP dislikes command console windows popping
up anywhere as much as I do. Of course, this only happens when a
procedure is launched by dropping a file onto it or a shortcut that
points to it. Or when it is run by double-clicking in explorer.
Other than that, there's probably no other downside.
Agreed. The downside is that most of us (and most of our scripts) assume
that the default is wscript.exe.

But the OP could modify his script to first determine which scripting engine
is being run, and re-run itself with cscript if if finds it is being run by
wscript. Then he can start the script by any method, whether by
double-clicking or typing scriptname.vbs at a prompt.

Alternately, he could create a non-standard filename extension (.vbsC) and
associate that with cscript.

/Al
Tom Lavedas
2010-02-19 14:06:11 UTC
Permalink
Post by Al Dunbar
Post by Tom Lavedas
Maybe a tiny one, if the OP dislikes command console windows popping
up anywhere as much as I do.  Of course, this only happens when a
procedure is launched by dropping a file onto it or a shortcut that
points to it.  Or when it is run by double-clicking in explorer.
Other than that, there's probably no other downside.
Agreed. The downside is that most of us (and most of our scripts) assume
that the default is wscript.exe.
But the OP could modify his script to first determine which scripting engine
is being run, and re-run itself with cscript if if finds it is being run by
wscript. Then he can start the script by any method, whether by
double-clicking or typing scriptname.vbs at a prompt.
Alternately, he could create a non-standard filename extension (.vbsC) and
associate that with cscript.
/Al
I have used the last approach, but I have not found it to be a perfect
solution. The problem I have found is that this does not support
piping of StdIn, which I found to be a significant disadvantage. At
least, I can't figure out how to get it to work.
_____________________
Tom Lavedas

Loading...