c#:是否可以将参数挂钩到现有进程。启动 iexplore.exe 然后使其导航到网站的示例
调用 Internet Explorer 的代码如下
System.Diagnostics.Process oProcess = new System.Diagnostics.Process();
oProcess.StartInfo.FileName = "C:\\Program Files\\Internet Explorer\\iexplore.exe";
oProcess.Start();
是否可以在该进程启动后为其分配 URL?
the code to invoke Internet explorer is as follows
System.Diagnostics.Process oProcess = new System.Diagnostics.Process();
oProcess.StartInfo.FileName = "C:\\Program Files\\Internet Explorer\\iexplore.exe";
oProcess.Start();
is it possible to assign a URL to this process once its started?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
或使用默认浏览器打开:
or to open with the default browser:
通过使用 Interop,这看起来是可能的。看看这个 codeproject 项目,它可以完成您想做的事情。
This looks possible by using Interop. Take a look at this codeproject project it does what you want to do.
是的,你可以这样做。您必须提供 URL 作为参数。看看这个。
Yes, you can do that. You have to provide URL as parameter. Have a look at this.
一般来说,“将参数挂钩到现有进程”是不可能的。您需要对相关应用程序有一定的了解并实施具体情况的解决方案。
但是,对于 IE(如您的示例),您很幸运,因为它可以使用 COM 进行控制。请参阅 adriaanp 的答案以获得干净的解决方案。
话又说回来,如果您今天碰巧心情不好,可能有一个更容易实现的解决方案。这绝不是执行此操作的正确方法,也不能保证在所有情况下都有效,但我已经在生产代码中看到过类似的方法。
这个想法是使用 Win API 来查找浏览器窗口,找到地址栏并输入您的 URL - 便宜,不是吗?通过这种方式,您可以消除所有 COM 依赖性,并且很快就能开始工作。
这是一些代码(只有一个公共方法
DoPopup
,您可以使用URL和浏览器窗口标题的一部分来调用它(您可以使用其他方式来获取浏览器窗口的句柄)如果你喜欢)):In general, it is not possible to "to hook arguments to an existing process". You'll need some kind of knowledge of the application in question and implement case-by-case solutions.
However, with IE (as in your example) you are in luck, as it can be controlled using COM. See the answer from adriaanp for a clean solution.
Then again, if you happen to be in a hackish mood today, there might be a simpler to implement solution. This is by no means the right way to do this, nor is it guaranteed to work under all circumstances, but I've seen something like this used in production code.
The idea is to use Win API to find the browser window, locate the adress bar and enter your URL - cheap, isn't it?! This way you eliminate all COM dependencies and you are rolling in no time.
Here is some code (there is only one public method
DoPopup
, which you call with the URL and some part of the caption of the browser window (you can use other means to get the handle of the browser window if you like)):