Get the PID of a Windows service

后端 未结 3 1401
星月不相逢
星月不相逢 2021-02-19 03:37

Could anyone help me to know how to get the PID of a Windows service?
I need to get the PID in order to run the following command:

Process.Start(new Process         


        
3条回答
  •  无人及你
    2021-02-19 04:10

    Assuming you know the name of the EXE the service uses and there is exactly one of them:

    int procID = Process.GetProcessesByName("yourservice")[0].Id;
    

    The method Process.GetProcessesByName("yourservice") returns an Array of Processes with your specified name, so in case you don't know how much of "yourservice.exe" runs simultaneously you might need a foreach loop.

提交回复
热议问题