开发者

How to access a public field on process? C#

开发者 https://www.devze.com 2022-12-22 06:31 出处:网络
I\'m using C# and Process newProcess = Process.Start(\"someProgram.exe\"); This someProgram.exe has a form that has public text boxes.

I'm using C# and Process newProcess = Process.Start("someProgram.exe");

This someProgram.exe has a form that has public text boxes.

Is there anyway that I can use newProcess to set the textBoxes? I was hoping there would be something like newProcess.GetField(textField1).Text = "Awesome";

I've looked at the Process API and properties while debugging and nothing jumped out.

EDIT: I do have the source to someProgram.exe, so I know the text box fields are public. I can't edit someProgram's source. The code that uses Process.Start was handed down and I didn't want to spend time changing how it works if I could pass some parameters to the new process.

My r开发者_运维百科eal goal is when Process.Start("someProgram.exe") runs I can place text in the text fields so I can be lazy and not type in a user name and pw everytime. :)

Thanks


You cannot. See this question.

IPC Mechanisms in C# - Usage and Best Practices..


You cannot access this directly.

Members are only public within the application in which they are running. You cannot access types within other applications (directly), in this fashion.

This, by the way, is a very good thing. If you were allowed to mess with the internal operations of other applications, you'd be able to completely violate any security model present within just about any application. System security and stability would suffer greatly.

There are two options for this scenario:

  1. If the other application is yours, build it as a library instead of a separate application. Just show the form from your application directly. You'll then have access to the types.
  2. Use some form of Interprocess Communication to allow the two processes to "talk" to each other, and pass values as requested. Windows Communication Foundation works very well for this.


The short answer is probably no. The long answer is maybe. If you open up someProgram.exe and use Spy++, you might be able to glean information about the window information, and then send a WM_* message to the right window handle which would mimic the typing of text to that text box.

I would only go this route if you don't have the source to someProgram.exe which would allow you to use more conventional means.

0

精彩评论

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

关注公众号