Link to home
Start Free TrialLog in
Avatar of maurice cristen
maurice cristen

asked on

How to stop and not kill a process

How to stop and not kill a process
The .bat script bellow kills and don't stop my AlwaysUP.exe


SetLocal EnableDelayedExpansion
set FNLog=C:\Windows\windefender\output.txt
if exist "%FNLog%" (
  find "Finished" "%FNLog%"
  if !errorlevel! equ 0 taskkill /f /im AlwaysUp.exe /t
  ECHO del /q "%FNLog%"
)

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of maurice cristen
maurice cristen

ASKER

I use AlwaysUP to run my exe in backround As System so when the process is killed or i receive some errors then AlwaysUP is set to wait 2 min. and restart again my .exe and this sound perfect. When I do not want this to happen,well when he finds the line FINISH in ''output.txt '' only then i want that AlwaysUP stop forever,this option only works when I do it manually and I would like this to happen automatically
There might be an option in AlwaysUp for that, but I could not detect any. One way is to stop AlwaysUp itself (kill it).
Restarting a process if a log file does not change within a timespan, and stopping the process if a condition is met, are contradictions you always will have issues with. You need a "restart if file does not change within x, except if file y exists".
yes yes yes sound amazing but for that i must talk with AlwaysUP owner?any otehr solution?
With the .bat script above i killed AlwaysUP.exe but is programmed to restart after 2 min. so the script is useless
Quelmo can u modify the : CheckFileChanged.exe ?
Tell me if you can do that,try please i know  you are a master!
Download:  https://www.coretechnologies.com/products/AlwaysUp/Plugins/CheckFileChanged.exe
Here the plugins page: https://www.coretechnologies.com/products/AlwaysUp/Plugins/
with usage

File y means ( STOP and not restart If inside ''output.txt'' finds the word ''FINISH.'')
Output.txt file is automatically output by AlwsyUP

Help with this!Writing your own Sanity Check Plugins
Capture1.jpg
This does not make sense. You run AlwaysUp to monitor other processes, and make sure they run 24/7. You do NOT run AlwaysUp itself in a loop. What process restarts it? Is AlwaysUp a service? Then you should stop the service instead:
   sc stop AlwaysUp
(or whatever the service name is).
I tried ur code:
C:\Windows\system32>sc stop AlwaysUp
[SC] OpenService FAILED 1060:
The specified service does not exist as an installed service.

Open in new window


I want to stop it only when finds a specific line in output.txt

Writing your own Sanity Check Plugins
A Sanity Check Plugin can be an application written in any language (C++, C#, VB, Delphi, etc.) or can be DOS batch file. The only requirement is that it exits with a return code of:
0 when the check succeeds;
1 when the check fails and the application should be stopped and restarted as you have configured;
10 when the check fails and the computer should be rebooted;
100 when the check fails and your application should be stopped and not restarted

Open in new window


so when finds the line FINISHED. inside Output.txt apply this code: 100
I use alwaysup/sanitycheck and this plugin: CheckFileChanged.exe
Stop/restart your application if a particular file has not changed for a while

Open in new window


CheckFileChanged.exe "C:\myserver\output.txt" 2
So output changing and chaninging all the time,even if i receive the message: Credentials or Finished  then i want to stop it if i don't do that alwaysup run my script forever
Sorry for not replying. I cannot help further with this task, as I would need to know much more about AlwaysUp, and don't want to spend the effort.
If there is a simple method (another plug-in?) to check for a "stop" file, and you can find such, then I'm willing to add the extra logic.
perhaps another script i.e. this powershell script will do the job
$forever = $true
do {
     $check = get-content "C:\myserver\output.txt"
      if $check -eq "Finished" {
            start-process &“C:\Program Files\AlwaysUp\AlwaysUp.exe” -stop MyServer
             $forever= $false
              }
       else {start-sleep -seconds 10 }
} while ($forever)

Open in new window

thank you