运行“应用程序参考”
我需要我的应用程序(Master)在特定事件上运行另一个应用程序(Worker)。
如果我将 Worker 应用程序作为标准可执行文件分发,那么一切都很好,我可以毫无问题地使用 Process.Start,并愉快地传递参数并调用 WaitForExit。
如果我将 Worker 应用程序作为 ClickOnce 应用程序分发,它会创建一个应用程序引用,我可以从 Process.Start 开始(一旦我将其副本放在与 Master.exe 相同的目录中) ,但我无法传递参数或使用 WaitForExit。
我希望能够两者兼得。我怀疑对引用的调用会启动 Worker 可执行文件实际运行的另一个进程。
我的代码:
// This works as I expect, and returns a valid Process.
Process p0 = Process.Start("Worker.exe", "DoSomeMagic");
// This seems to work, but returns null.
Process p1 = Process.Start("Worker.appref-ms");
// This also returns null, but does not pass the argument to Worker.
Process p2 = Process.Start("Worker.appref-ms", "DoSomeMagic");
我的问题:
如何“正确”执行此操作?
I need my application (Master) to run another application (Worker) on a particular event.
If I distribute my Worker application as a standard executable, then all is well, and I can use Process.Start with no problems and happily pass in arguments and call WaitForExit.
If I distribute my Worker application as a ClickOnce Application, it creates an Application Reference, which I can start with Process.Start (once I put a copy of it in the same directory as my Master.exe), but I cannot pass it arguments or use WaitForExit.
I want to be able to do both. I suspect the call to the reference starts another process which the Worker executable actually runs in.
My code:
// This works as I expect, and returns a valid Process.
Process p0 = Process.Start("Worker.exe", "DoSomeMagic");
// This seems to work, but returns null.
Process p1 = Process.Start("Worker.appref-ms");
// This also returns null, but does not pass the argument to Worker.
Process p2 = Process.Start("Worker.appref-ms", "DoSomeMagic");
My question:
How do I do this "properly"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认情况下,ClickOnce 应用程序不允许传递命令行参数(或者在其情况下,通过查询字符串传递参数)。您需要在清单文件中配置适当的选项才能允许它们,但即使如此,也需要考虑一些注意事项。整个 ClickOnce 平台对应用程序的执行方式以及启动方式施加了一些非常严重的限制。当然,这都是打着安全的幌子,但我个人认为这是短视的行为。
有关如何将参数传递给 ClickOnce 应用程序的更多信息,请访问:http://msdn。 microsoft.com/en-us/library/ms172242.aspx
ClickOnce applications do not allow the passing of command-line arguments (or, in their case, arguments by query string) by default. You need to configure the appropriate option in the manifest file in order to allow them, but even then there are several caveats to consider. The whole ClickOnce platform imposes some very nasty limitations on how your applications can execute, as well as how they can be started. Of course, this is all under the guise of security, but personally I think it's short-sightedness.
More info here on how to pass arguments to ClickOnce apps: http://msdn.microsoft.com/en-us/library/ms172242.aspx