如何访问进程上的公共字段? C#

发布于 2024-08-23 20:51:35 字数 492 浏览 5 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

思念绕指尖 2024-08-30 20:51:35

您无法直接访问它。

成员仅在其运行的应用程序内是公开的。您无法以这种方式(直接)访问其他应用程序中的类型。

顺便说一句,这是一件非常好的事情。如果您被允许干扰其他应用程序的内部操作,您将能够完全违反几乎任何应用程序中存在的任何安全模型。系统的安全性和稳定性将受到极大影响。

对于这种情况有两种选择:

  1. 如果另一个应用程序是您的,则将其构建为库而不是单独的应用程序。只需直接出示您的申请表即可。然后您就可以访问这些类型。
  2. 使用某种形式的进程间通信来允许两个进程相互“交谈”,并根据要求传递值。 Windows Communication Foundation 对此非常有效。

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.
夏至、离别 2024-08-30 20:51:35

简短的回答可能是否定的。长答案是也许。如果您打开 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文