如何在C#中远程控制cmd.exe进程
我真的被一个问题困扰了(现在已经7天了),在我发疯之前我想我应该寻求建议。
我想做的基本上就是启动并远程控制一个cmd.exe进程。然而,StandardInput 和 StandardOutput 流并不能完成这项工作,因为它们不是由等待用户输入的“mysql”等命令触发的。
所以我想要的只是读取 cmd.exe 控制台的内容并写入它。但是 write 方法应该能够触发新命令。
我尝试了很多,我很确定 kernel32.dll 可以解决这个问题:
- ReadConsoleOutput()
- WriteConsoleInput()
- GetConsoleScreenBufferInfo()
- SetConsoleCursorPosition()
当然我已经有一些东西可以工作,但我绝对不确定是否我走对了路。因此我不会发布任何代码,因为它可能会让您感到困惑。
如果有人能给我指点一个有效的演示或教程或类似的东西,那就太棒了。即使它是 C++ 或 C - 也比没有好。
提前致谢。
Mewes Kochheim
PS:请不要只发布 pinvoke 或 MSDN 的链接,我需要的是更复杂一点的。看来我没有足够的 winapi 经验来独自到达那里:/
编辑:我必须尝试根据你们发布的链接得到的一些新想法。我会回来并发布我的想法。谢谢你们的帮助...
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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在这里您可以找到几个有关“远程控制命令提示符”的示例“...
另一个链接(.NET这次来自stackoverflow)。 ..
和来自 Visualstudio 杂志的内容...
here you find several examples regarding "remote control of command prompt"...
another link (.NET this time from stackoverflow)...
and something from visualstudio magazine...