tags:

views:

81

answers:

3

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 real 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

+2  A: 

You cannot. See this question.

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

ChaosPandion
A: 

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.
Reed Copsey
Both apps are mine.I thought of this, but the code I have was handed down and its a side/personal project that i was looking at. I wanted to do it with the least amount of work. I'll look into #2 Thanks
Brad8118
A: 

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.

Nick