Link to home
Start Free TrialLog in
Avatar of adinas
adinas

asked on

Controlling a DOS window from inside VB

What I want to do is be able to send key clicks (type as though i am using the keyboard) to a DOS window. The following code works with Windows programs but besides opeing the DOS window and doing some wierd things, did not work:

Private Sub Command1_Click()
Dim ReturnValue, I
ReturnValue = Shell("C:\command.com", 1)  
'MsgBox ReturnValue
AppActivate ReturnValue    ' Activate
SendKeys "X", True


End Sub
Avatar of sp_phillips
sp_phillips

There's an answer on the new Microsoft MSDN Code Site

http://msdn.microsoft.com/code
The best way is using the API

i.e.

AllocConsole
FreeConsole
CloseHandle
GetStdHandle
WriteConsole
SetConsoleCtrlHandler

The example wraps this up in a class wrapper, so it's easy to manipulates

You'll find this in Code Exapmles\Visual Studio, Tools & Lanuages\Visual Basic\Console Window

Simon
ASKER CERTIFIED SOLUTION
Avatar of hes
hes
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of adinas

ASKER

OK. I see i didn't explain myself well. The code you showed me indeed created a console which accepts keyboard and mouse input but I wanted to control a REAL DOS window. I want to be able to run a certain DOS App and then send key input to it (from inside my program) for example: I would open a DOS window and my program would type "DIR" and then the Enter key and then the DOS window would show the results.