Send keys from .NET APP to an old APP

G

Go Perl

Hello

Here is an interesting question which I could not solve it.

I have an old dos app for which source code is lost. I just have the
exe file. So I have created a front-end for that. I linked the
front-end to the back end exe file.

Everything works fine except When I hit a button on the front end it
brings up the dos app and I have to manually enter few key presses
like F, F, N and ENTER or ESC for dos app to run an algorithm and
output the results to a file.

If only I could send these keystrokes from my c# app to this old exe
file, I could automate this process and the user will not have to see
the old exe file.

I tried using sendkeys.sendwait, but it is working on cmd.exe but not
passing the keystrokes to this old app. Possibly, because it is
sending just characters that are not recognized.

If anyone has an idea to solve this please reply to this message . I
would greatly appreciate the help and it will help me from re-writing
thousands of lines of code.


Regards,
..NET Coder
 
B

Bob Grommes

SendKeys.SendWait() works fine for a Windows app that I have to start and
then dismiss an initial dialog box -- even though my controlling app is a
console app.

I doubt it would work when *targeting* a console app however. Any chance
you could send the keystrokes to stdin instead?

--Bob
 
D

Drebin

Agreed, if you get a handle to the process, you could so something like:

objProcess.StandardInput.Write("this should show up in the console");
 
D

Drebin

I was trying to work up a working example,but ran into some roadblocks.. to
get a handle to that app, you can do this:


System.Diagnostics.Process[] procProcesses =
System.Diagnostics.Process.GetProcesses();

foreach (System.Diagnostics.Process procActiveProc in procProcesses)

{

if ( procActiveProc.MainWindowTitle == "whatever" )

{

// Do something - procActiveProc is a handle to that whole process now

}

}



But what I was thinking, was doing something like this:



procCmdWindow.StartInfo.RedirectStandardInput = true;

procCmdWindow.StartInfo.UseShellExecute = false;

procCmdWindow.StandardInput.Write("dir *.*\n\rdir");


But really, that is for when you create your own process.. I couldn't find
how to redirect stdin one the app is already running.. so, although I still
think this "can" be done somehow, I'm about out of ideas.

If nothing else, I've shown a way it *can't* be done!! :) good luck!
 
B

Bob Grommes

The Process class has a static method for finding processes by name. See
what the EXE you're talking about is called in Task Manager's process list,
and have your code search for that name.

--Bob
 

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