0

I am creating a windowservice that starts a process where I pass multiple cmd arguments in the StartInfo.Arguments. That works fine as expected.

The problem is that when i stop the windowsservice, I need to tell the running program to shut down gracefully before the windows service stops. Because if I just kill the process the program does not save the collected data. The program that I run is the Process Monitor and it accepts the following command "/terminate".

How can I pass the /terminate argument before my windows service stops?

3
  • 2
    Can't you use a batch file which first closes the running program with start /wait, then stops the service with sc stop command?
    – AFH
    Commented Jun 23, 2018 at 14:14
  • @AFH Thanks for the comment. Well I would like to keep all the code within the service itself. Anyway I just got punked for asking this question on a couple of other stack sites. So I guess my question is not 100% fitting for this forum, but I managed to find a solution. I needed to create a new instance of the process monitor and pass the /Terminate argument and with that it stoppes all process monitor instances gracefully.
    – IceCode
    Commented Jun 23, 2018 at 15:29
  • 1
    @Örvar You can answer your own question
    – DavidPostill
    Commented Jun 23, 2018 at 15:53

1 Answer 1

0

I managed to find a solution. In the OnStop() method in the service, I needed to create a new instance of the Process Monitor and pass the /Terminate argument:

Process process = new Process();
process.FileName = "\Procmon.exe" ;
process.StartInfo.Arguments = "/AcceptEula /Terminate";
process.Start();

With that it stoppes all the Process Monitor instances gracefully.

2
  • What language is this code written? Commented Jun 23, 2018 at 16:48
  • @PimpJuiceIT C# I have added it as a Tag.
    – IceCode
    Commented Jun 23, 2018 at 16:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .