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

Roy_37

Prominent
Mar 2, 2017
1
0
510
0
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
 

Ralston18

Dignified
Moderator
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.
 
Thread starter Similar threads Forum Replies Date
P Apps General Discussion 3
F Apps General Discussion 1
T Apps General Discussion 1
J Apps General Discussion 1
R Apps General Discussion 3
AR_4 Apps General Discussion 1
moonfang158 Apps General Discussion 2
M Apps General Discussion 1
J Apps General Discussion 2
S Apps General Discussion 2
NoctisLionward Apps General Discussion 2
E Apps General Discussion 9
J Apps General Discussion 3
H Apps General Discussion 1
O Apps General Discussion 4
N Apps General Discussion 2
C Apps General Discussion 1
mjmcdonagh1 Apps General Discussion 2
L Apps General Discussion 3
J Apps General Discussion 1

ASK THE COMMUNITY