如何访问进程上的公共字段? C#
我正在使用 C# 和 Process newProcess = Process.Start("someProgram.exe");
该 someProgram.exe 有一个包含公共文本框的表单。
无论如何,我可以使用 newProcess 来设置文本框吗? 我希望会有像 newProcess.GetField(textField1).Text = "Awesome"; 这样的东西
我在调试时查看了 Process API 和属性,但没有发现任何问题。
编辑: 我确实有 someProgram.exe 的源代码,所以我知道文本框字段是公共的。我无法编辑某些程序的源代码。 使用 Process.Start 的代码已被传承,如果我可以将一些参数传递给新进程,我不想花时间改变它的工作方式。
我真正的目标是当 Process.Start("someProgram.exe") 运行时,我可以在文本字段中放置文本,这样我就可以偷懒,而不是每次都输入用户名和密码。 :)
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你不能。看到这个问题。
C# 中的 IPC 机制 - 用法和最佳实践..
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:
简短的回答可能是否定的。长答案是也许。如果您打开 someProgram.exe 并使用 Spy++,您也许能够收集有关窗口信息的信息,然后将 WM_* 消息发送到右侧窗口句柄,这将模仿在该文本框中键入文本。
如果您没有 someProgram.exe 的源代码(这将允许您使用更传统的方法),我只会走这条路。
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.