Jump to content











Photo
- - - - -

Auto-kill running process if a specified process is not running, otherwise let it run?


  • Please log in to reply
3 replies to this topic

#1 AnonVendetta

AnonVendetta

    Silver Member

  • Advanced user
  • 781 posts
  • Location:A new beginning.....
  • Interests:Self-development, computing

Posted 04 March 2020 - 09:09 AM

Ok, so first, this isnt a booting question. I have a program that must remain running in the background if another specific process is running. Problem is, it doesnt autoexit when said process has ended. So i would like to create a bat or cmd file that:

1. Starts launcher process
2. Launcher process starts subprocess
3. Scans for a specific process, and allows that process's launcher exe to remain running if true
4. If false and the launched process isnt running, I would like to autokill that process's launcher exe

It is 2 processes in total, but the 2nd wont run if it detects the 1st process isnt running. I just am looking for an easy, scriptable solution. Ideally it (the bat/cmd) will poll once per minute, kill the launcher process if its' subprocess is no longer running, then cleanly exit.

Thanks!

#2 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 15396 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 04 March 2020 - 10:25 AM

Basically you need:

tasklist

https://ss64.com/nt/tasklist.html

 

taskkill

https://ss64.com/nt/taskkill.html

 

timeout

https://ss64.com/nt/timeout.html

 

The issue - generally speaking - with doing this in batch is that timeout or sleep or ping consume processor cycles.

 

Maybe you could try using the task scheduler (schtasks) directly or through soon.exe (win2K resource Kit), but AFAICR each version of Windows is slightly different (if it is Windows you are asking about),  Nirsoft's ATnow should be easier:

 

https://www.nirsoft....tils/atnow.html

 

:duff:

Wonko



#3 karyonix

karyonix

    Frequent Member

  • Advanced user
  • 473 posts
  •  
    Thailand

Posted 05 March 2020 - 10:51 AM

Can the actual app work if it is invoked from another program while the launcher run in background ?

Can you configure the launcher not to run the actual app automatically ?

 

If both are yes, a simple batch file like this may work.

 

launchername.exe

start /wait "" appname.exe

taskkill /im launchername.exe



#4 AnonVendetta

AnonVendetta

    Silver Member

  • Advanced user
  • 781 posts
  • Location:A new beginning.....
  • Interests:Self-development, computing

Posted 11 March 2020 - 11:33 PM

@karyonix: The launched subprocess checks the name of the launching process, as well as its' digital signature. It also periodically checks for the launcher while running, and will exit if not found. So, the launcher must remain running.

I'm looking into Wonko's suggested solution, it should be enough. Since my only need is to auto kill the launcher if its' subprocess isn't running.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users