Script to check running process and finish or not

Asked

Viewed 2,306 times

2

i have a process called monitor.exe and the same can not have 2 active processes because it is a print monitor that if you have 2 active processes the same will issue 2 duplicate tax notes, so I wonder if there’s a way I can make a script that checks if the process is active, if there’s only 1 active and if there’s more than 1 finish and only 1 active ?

I tried to make a simple script with taskkill /F /IM monitor.exe and then run a start path from . exe\

but sometimes when I finish the process it goes up there alone if I give the start are the 2 duplicated again, someone has some idea ?

  • This "monitor.exe", you developed? In which language is this monitor made? Maybe validation should be within the system itself.

  • the system is not mine, it is outsourced, so I am having to do this script because I do not have access to the application code

  • bash is a relevant tag here?

  • is relevant because there is a bash for windows

1 answer

0


The command wmic process where name="monitor.exe" | find "monitor.exe" /c returns the amount of file processes monitor.exe running.

In order to be able to check the amount of processes running we can save the result of this command in the variable %pcount% with the script below:

@echo off

set pname=monitor.exe

set pcommand="wmic process where name="%pname%" | find "%pname%" /c"

FOR /F "tokens=*" %%i IN (' %pcommand% ') DO SET pcount=%%i

if %pcount% GTR 1 (
    echo Tem mais de um processo.
    taskkill /f /im %pname%
    start pasta\para\%pname%

) else (
    echo Tem um ou nenhum processo.
)
pause
  • Duplicate question ... you’ve asked this question here and I’ve already answered it. https://answall.com/questions/291737/script-para-identificar-2-activeservices-downing os-2-up-apenas-1

  • Cristian, in vdd one is for a service the other is for a process

  • just edit the script, the process is the same for processes

Browser other questions tagged

You are not signed in. Login or sign up in order to post.