I need to run "WScript" File help!!

T

tjdarth

Hey guys, I have run across a situation where I need to run a (.js) type
wscript on my Win-XP SPIII system. When I place the short script on my
Desktop and Double-click to start the process, I am surprised to have my
Dreamweaver CS3 application startup. I go on the prowl and sure snuff' I
find that the (.js) file type is associated with amoung other things
Dreamweaver CS3.
I took the liberty to look-see how the (.vbs) file was handling its process,
and it appears that it is dependent on the following "Microsoft(R) Windows
Based Script Host" processor. I'm not sure how to attach this application to
my specific (.js) file.

Is there a possible way to give me the best of both worlds, or will I have
to do some follng' around?

Any help would be appreciated . . .

Tom J.
 
J

ju.c

Change the extension to VBS or enter in the Run box or command
window:

csript "C:\Path To\file.js".

If that works for you you could create a context menu item to run JS
files by right-clicking them. (Right-click "Run JS File")


ju.c
 
T

tjdarth

Thanks ju for your quick response. At your suggestion, I changed the file
type to (.vbs) and used the RUN command to execute the
script. The result is a quick cmd window flash before it closes and I still
have not successfully accomplished what I set out to do in the first place,
which is to start a Windows application thru WScript. The simple script that
I am trying to run is included below:

var WshShell = new ActiveXObject("WScript.Shell");
var dirfile= I:\Program Files\HP\Digital Imaging\bin\Hpqdirec.exe;
//execute this file!!!
var oExec = WshShell.Exec(dirfile);
WScript.Sleep(3000);
WshShell.SendKeys("%( )"); //equivalent of Alt+spacebar
WshShell.SendKeys("nn"); //equivalent of click minimize twice
oExec = WshShell.Exec(dirfile);

This is just a straight forward script that I want to start my Windows
application, but nothing else happens. Does anything look amist to you?

Thanks for your help . . .
Tom J.
 
B

Bill Blanton

If you open a cmd prompt first and then run the file, and the cmd Window
will not disappear, and you may see an error message.

cscript yourfile.js

Try wrapping the dirfile variable string in " "
var dirfile= "I:\Program Files\HP\Digital Imaging\bin\Hpqdirec.exe";
 
T

tjdarth

Thanks Bill for your suggestion. After placing the dirfile in " ", I get an
error messag on line 3 which is simply trying to set the variable "oExec" to
the command WshShell.exe I get the msg: The system cannot find the file
specified -->WshShell.exe! Indeed when I look in system32\ dir the wscript
exe is there but the WshShell.exec is not? Is this appl suspiciously hidden
somewhere else?

Thanks again . . .Tom.J
 
B

Bill Blanton

That msg is most likely reporting that it isn't finding the file Hpqdirec.exe.
WshShell.Exec is an internal script procedure; in this case to launch (dirfile).
The parameter passed is most likely wrong. Are you sure there are no typos
in the path\name ?
 
B

Bill Blanton

I'm crossposting this to the NG that's more expert on the matter.
(to vbscript; see code below)
 
T

tjdarth

Thanks Bill, I have checked & rechecked and the spelling is correct. In fact
I extracted the entire Dir file string from the target string field of the
programs ICON, so that was my reasoning of looking for the WshShell.Exec
application. Its' apparent that I don't know a whole heck of a lot about
this cmd line shell process. I am grateful for your help. I am not sure
where else to look.

Thanks again . . .Tom J.
 
J

James Whitlow

tjdarth said:
Thanks ju for your quick response. At your suggestion, I changed the file
type to (.vbs) and used the RUN command to execute the script. The result
is a quick cmd window
flash before it closes and I still have not successfully accomplished what
I set out
to do in the first place, which is to start a Windows application thru
WScript. The
simple script that I am trying to run is included below:

var WshShell = new ActiveXObject("WScript.Shell");
var dirfile= I:\Program Files\HP\Digital Imaging\bin\Hpqdirec.exe;
//execute this file!!!
var oExec = WshShell.Exec(dirfile);
WScript.Sleep(3000);
WshShell.SendKeys("%( )"); //equivalent of Alt+spacebar
WshShell.SendKeys("nn"); //equivalent of click minimize twice
oExec = WshShell.Exec(dirfile);

Try giving it a '.wsf' extension and wrapping it in the XML '<job>' &
'<script>' tags. I tested the below code on my computer (using 'notepad.exe'
renamed as 'Hpqdirec.exe') and it worked. I did have to wrap the path and
double up the slashes, though.

<job>
<script language="javascript">
var WshShell = new ActiveXObject("WScript.Shell");
var dirfile= "I:\\Program Files\\HP\\Digital Imaging\\bin\\Hpqdirec.exe";
var oExec = WshShell.Exec(dirfile);
WScript.Sleep(3000);
WshShell.SendKeys("%( )"); //equivalent of Alt+spacebar
WshShell.SendKeys("nn"); //equivalent of click minimize twice
oExec = WshShell.Exec(dirfile);
</script>
</job>
 
J

James Whitlow

James Whitlow said:
Try giving it a '.wsf' extension and wrapping it in the XML '<job>' &
'<script>' tags. I tested the below code on my computer (using
'notepad.exe' renamed as 'Hpqdirec.exe') and it worked. I did have to wrap
the path and double up the slashes, though.

Woops, I forgot to double up the backslashes in the code above. I also
meant to say, 'wrap the path in quotes'.

I did notice that I could just turn the backslashes into forward slashes &
then I don't have to double them up. I also noticed I could use single
quotes instead of double quotes. I work with WSF files a lot, but
exclusively with VBScript and not JavaScript, so I have very little
knowledge of the language itself.

<job>
<script language='javascript'>
var WshShell = new ActiveXObject("WScript.Shell");
var dirfile= 'I:/Program Files/HP/Digital Imaging/bin/Hpqdirec.exe';
var oExec = WshShell.Exec(dirfile);
WScript.Sleep(3000);
WshShell.SendKeys("%( )"); //equivalent of Alt+spacebar
WshShell.SendKeys("nn"); //equivalent of click minimize twice
oExec = WshShell.Exec(dirfile);
</script>
</job>
 
T

tjdarth

Thanks for your help James. I too got this thing to work after adding in the
XML <job>, <script> tags AND changing the "\" to "/" and changing the
filetype to (".wsf"). This should bring closure to this problem at this
time. Thanks tons... . . . . Tom J.
 
T

tjdarth

Bill, I finally got an answer and solved my problem. Take a look at the
crossposting. Thanks agin for all your help as well.

Tom J.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top