开发者

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

开发者 https://www.devze.com 2023-03-28 12:17 出处:网络
I\'m really stuck with a problem (for 7 days now) and before I go crazy I thought I\'ll just ask for advice.

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 remot开发者_开发百科e 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...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号