running scripts/DOS commands in a cmd console

Posted by Amstel on Wed 26 Mar 2003 09:14 PM — 2 posts, 22,859 views.

#0
hi all,

i'm trying to write an hta application that uses WSH. i want to run serious of

commands/batch files in one single cmd console invoked by my application.

this is part of the code:

var WshShell = new ActiveXObject("WScript.Shell");
WshShell.Run("cmd",2); //create cmd console minimized
WshShell.AppActivate("C:\\WINNT\\System32\\cmd.exe");
WshShell.SendKeys ("dir~"); //run 'dir' command and 'enter'

the problem is that multiple cmd consoles are created and not one...

can any of you help???

thanks,
amstel
Australia Forum Administrator #1
Can't you just put the multiple lines as SendKeys, like this?

WshShell.SendKeys ("dir~"); //run 'dir' command and 'enter'
WshShell.SendKeys ("cd /~");
WshShell.SendKeys ("notepad test.txt~");