在代码中启动多个进程并在命令行参数中区分它们

发布于 2024-08-02 14:42:32 字数 424 浏览 3 评论 0原文

我正在运行一个服务程序,该程序使用命令行传递的不同配置文件多次启动。 该程序由作为 Windows 服务运行的控制程序启动。该服务应该能够监视和重新启动程序。 目前我遇到的问题是,如果控制程序崩溃,我无法启动服务程序的所有实例,因为我无法检测哪个实例正在运行,哪个实例没有运行。

我尝试使用 System.Diagnostics.Process API 和 WMI API 来获取一些信息。 但在这两种变体中,命令行参数都不可用。

为了启动一个实例,我使用 System.Diagnostics.Process 的 StartInfo 对象。我在 stackoverflow 的某处读到 StartInfo 对象中的进程信息不可用于另一个进程,但它应该由 WMI API 提供 - 但在我的情况下不是..

我是否必须以另一种方式启动实例或以另一种方式存在访问正在运行的进程的命令行参数

I am running a service program which is started multiple times with different configuration files passed on commandline.
The program is started by a control program which is running as windows service. This service should be able to monitor and restart the programs.
At the moment i have the problem if the control program crashes, i can not start all the instances of the service program, because i can not detect which instance is running and which is not running.

I tried using the System.Diagnostics.Process API and also the WMI API to get some information.
But at both variants the Commandline arguments are NOT available.

To start an instance i am using the StartInfo-object of the System.Diagnostics.Process. I read somewhere at stackoverflow that the process information within the StartInfo object is not available to another process, but it should be available by the WMI API - but not in my case ..

Do i have to start the instances another way or exists another way to access the commandline arguments of a running process

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

旧时模样 2024-08-09 14:42:32

我更改了此设置以使用 System.Management 命名空间。现在列出了检测到的进程。但我必须使用正则表达式处理整个命令行..这是唯一的“坏”事情

I changed this setup to use System.Management Namespace. Now the processes are listed detected. But i have to process the whole commandline using regular expressions .. that's the only "bad" thing about that

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