开发者

How to communicate with a separate application from c#

I have an .exe that runs on my computer. 开发者_高级运维How can I connect to it from c#?

For example notepad.exe is running. I would like to write in notepad from windows form app or console app form. How can I do that?


Two suggestions:

either start the process using Process.Start()

http://msdn.microsoft.com/en-us/library/system.diagnostics.process.start.aspx

or use SendKeys from Windows Script Host

http://msdn.microsoft.com/en-us/library/8c6yea83(VS.85).aspx


It depends on exactly what you want to do. Using SendKeys is the simplest solution but it's crude and limited in functionality. You can do more and better with SendMessage, but this will be harder to code.


Have a look at this tutorial. As far as I can tell, it does exactly what you are looking for. I realize it's in German, so just look at the source code.


Reading from another process in windows is problematic to say the least. We did some work on this a while ago and it involved hooking into the low-level Win32 API using assembly language. Essentially, it's really not pleasant and if you can avoid doing this you'll have a lot more hair on your head.

Using SendMessage would work if the application you are sending to understands the message you are trying to send to it. I suspect that you start to get into security problems with this on later Windows versions (Vista + Win7) and would have to run your application with elevated privileges.

Why do you want to do this?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜