简体   繁体   中英

How to remote control a cmd.exe process in C#

I'm really stuck with a problem (for 7 days now) and before I go crazy I thought I'll just ask for advice.

Want I want to do is basically to start and remote control a cmd.exe process. However the StandardInput and StandardOutput streams don't do the job, since they aren't triggered by commands like "mysql" which wait for a user input.

So all I want is to read the content of the cmd.exe console and write to it. However the write method should be able to fire a new command.

I tried a lot and I'm quite sure the kernel32.dll will do the trick:

  • ReadConsoleOutput()
  • WriteConsoleInput()
  • GetConsoleScreenBufferInfo()
  • SetConsoleCursorPosition()

Of course I already have some stuff working, but I'm absolutly not sure whether or not I took the right road. Therefore I won't post any code since it would probably just confuse you.

It would be awesome if someone could point me to a working demo or tutorial or something like that. Even if it's C++ or C - would be better than nothing.

Thanks in advance.

Mewes Kochheim

PS: Please don't post just a link to pinvoke or MSDN, what I need is little bit more complex. And it seems like I don't have enough winapi experience to get there on my own:/

Edit: I've to try out some of the new ideas I got based on the links you guys posted. I'll will be back and post what I figured out. Thanks for the help guys...

here you find several examples regarding "remote control of command prompt"...

another link (.NET this time from stackoverflow)...

and something from visualstudio magazine...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM