Close Service if programm is closed

Discuss RoboTask here
datroubler
Posts: 9
Joined: Thu Oct 18, 2012 8:58 am

Close Service if programm is closed

Post by datroubler »

What I like to do is that RoboTask checks if an application ( in this case Cisco AnyConnect) is still running (symbol is shown besides the clock) and if it isn't running anymore the service should be shut down. How can i realise that?
Oleg
Site Admin
Posts: 3202
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Close Service if programm is closed

Post by Oleg »

You can check process existence and do something in compliance with result.
Look at {IsProcessExists()} variable
Usage:
{IsProcessExists(<Program_EXE_File>)}
This returns TRUE or FALSE

Algorithm will be similar:

if {IsProcessExists(MyApp.exe)}= true then
   ...
   Do something
   ...
Else
   ...
   Do something else
   ...
End If
datroubler
Posts: 9
Joined: Thu Oct 18, 2012 8:58 am

Close Service if programm is closed

Post by datroubler »

I managed to first start the service and then start the programm.I know a bit about programming (java) but i dont know where to add the code which you wrote.
Oleg
Site Admin
Posts: 3202
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Close Service if programm is closed

Post by Oleg »

I see that you start service and then you start some application....
What next? What your goal?
What I like to do is that RoboTask checks if an application ( in this case Cisco AnyConnect) is still running (symbol is shown
besides the clock) and if it isn't running anymore the service should be shut down.
It seems you want to stop the service when the program vpnui.exe will be done. This is correct?

In this case create new task with the following algorithm:

if {IsProcessExists(MyApp.exe)}= False then
   Stop service vpnagent
End If

You can attach Cyclic trigger to the task.
This task will stop service when vpnui.exe will be finished.
datroubler
Posts: 9
Joined: Thu Oct 18, 2012 8:58 am

Close Service if programm is closed

Post by datroubler »

Yes you got it right.So I can't integrate this function in the already running task?The question sounds stupid but where can I add the code?
Oleg
Site Admin
Posts: 3202
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Close Service if programm is closed

Post by Oleg »

Why do you want to put ALL functions into ONE task???
Sometimes this is VERY unhandy.

Let one task will start service and necessary program
Another task checks status of your program periodically and closes service when program will be finished.
Last edited by Oleg on Fri Oct 19, 2012 10:42 am, edited 1 time in total.
datroubler
Posts: 9
Joined: Thu Oct 18, 2012 8:58 am

Close Service if programm is closed

Post by datroubler »

Ok but still the question:where to put the code?And how to start both tasks with one click?
Last edited by datroubler on Fri Oct 19, 2012 11:00 am, edited 1 time in total.
Oleg
Site Admin
Posts: 3202
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Close Service if programm is closed

Post by Oleg »

There are two tasks. Download here:
1-st task.tsk
2-nd task.tsk

Save tasks to files and use menu Task->Import in order to import into RoboTask. Don't forget to enable both tasks after importing.

2-nd task will run automatically. You don't need start it manually at all
datroubler
Posts: 9
Joined: Thu Oct 18, 2012 8:58 am

Close Service if programm is closed

Post by datroubler »

Wow thanks a lot, works fine. But one question to the second task: Is it running since windows started? I have several programms in which i would like to use this algorithm. Isn't it a prolem for the performance if it checks every 15 seconds if the process is running?Wouldn't it be better so start the second task after the first task?edit:next question:is it possible to (de)activate network adapters?




Last edited by datroubler on Fri Oct 19, 2012 3:44 pm, edited 1 time in total.
Oleg
Site Admin
Posts: 3202
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Close Service if programm is closed

Post by Oleg »

You don't need to start 2-nd task. Just enable it like this:

Start service
Run program
Enable "2-nd task"

at 2-nd task:

if {IsProcessExists(vpnui.exe)} = False then
   Disable "2-nd task"
   Stop service vpnagent
End If

When you enable task the trigger begin to work and start the task automatically.
BTW: you can set any period: 1 min or 15 min, as you wish.

You may download examples again. I have updated them:
1-st task.tsk
2-nd task.tsk
Post Reply