Sending Command to DOS / Automating DOS

susan_atkins used Ask the Experts™

I'm working on a small application that i wanted to havce automate DOS t a certain degree.  what I want is really very simple.  I want a small VB form that will open DOS and then automatically load one of four commands (depending on which button is clicked) and wait for the output.  The DOS window wouldn't even need to close itself.

I was able to bring up the DOS window but then I've been stuck with the whole passing keystrokes to it.  Lateluy I've been trying to use AppActive but every time I try to use it, I get an error.  Usually: 'Invalid Outside Procedure' / Run Time error 5.  My MSDN Help is gimped so I've been trying to find out what i can online, and from what I've seen, I still can't figure out what I'm doing wrong.

here's the code I'm trying to make work - all I want it to do, is open the DOS window (which it does) and then load in and execute to change directory command:

Private Sub Form_Load()
    Dim the_command As String
    the_command = ""
    Shell the_command, vbNormalFocus
    AppActivate "the_command"
    SendKeys ("cd c:\")
End Sub
could someone *please* let me know where I'm going wrong on tis?  It seems like this should be a sort of easy thing and I can't understand why I'm having such a hard time with it!

Please let me know if you need any other details / clarificatin -


Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
AppActivate "the_command" is incorrect unless your command window has the words "the_command" in the title.  The Invalid outside procedure isn't from anything you have listed here.  You probably have a call or line of code that is not a declaration in the General Declarations section.

Probably the easiest way to perform what you are asking is to set up Batch files (with a .Bat extension) that will perform the DOS commands you wish to use.  Then when you shell, use that batch file name as you did with command.exe

MyBatch looks like:
cd c:\
rem pause if you want to see the results remove if you don't care

   Dim the_command As String
   the_command = "c:\Mybatch.bat"
   Shell the_command, vbNormalFocus


Much thanks for the advice on batch files!  I knew I had to be missing *something* but the more I tried to sort it out, the more lost I got!

Much thanks again!  I wrote the commands to batch files and had them execute directly.  One side question, though - this works beautifully on 9x but when it was loaded on 2000 & NT the DOS window just pops up and then closes again.  Any ideas?


That's why I had the pause command put in the sample batch file I showed you.  

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial