Powershell help, start a service only if an application is launched.

Roy_37

Prominent
Mar 2, 2017
1
0
510
I need assistance. Very newbie to ps. I need a script that starts a certain service only if a certain app is launched. And then stop the service if the application is closed. Any guidance is appreciated.

Note: The service needs to start prior to this application started. I don't want it automatically started when the system boots up. Long story.

Perhaps a batch file will help to start the process in this order.
1. Start Service
2. Start application
3 If app.exe closes, stop service
 
Solution
The logic needs to be reconsidered:

You cannot start a service prior to the start of some application without some flag or other information that the application is going to be started.

What that "flag" may be is something you need to consider. Code cannot be clairvoyant.

That said:

Write a script as best you can.

Do it in steps. Very roughly something along the following:

1) Detect that that a request to start the app has been made.

2) Establish a conditional that recognizes that request and starts the service.

3) Proceeds with the app start once the service is started.

4) Establish what happens when the application is closed.

Write, test, and post the script if there are problems.

Should be a fairly straightforward bit of...
The logic needs to be reconsidered:

You cannot start a service prior to the start of some application without some flag or other information that the application is going to be started.

What that "flag" may be is something you need to consider. Code cannot be clairvoyant.

That said:

Write a script as best you can.

Do it in steps. Very roughly something along the following:

1) Detect that that a request to start the app has been made.

2) Establish a conditional that recognizes that request and starts the service.

3) Proceeds with the app start once the service is started.

4) Establish what happens when the application is closed.

Write, test, and post the script if there are problems.

Should be a fairly straightforward bit of code.

Seems to be a homework assignment and we cannot do homework. Against Forum rules.
 
Solution