M
M
Moolzv Rivers2019-10-20 22:58:21
cmd/bat
Moolzv Rivers, 2019-10-20 22:58:21

How to check if a process is running and if it is not running, start it?

Hello.
I need to protect the program in case of a suspicious process, that is, if the process is detected - enable protection, I want to do it like this:
1. Create a bat file, run it and it will constantly check if my "antivirus" is running, if it is closed - run it again
2. Create a VBS file and run and check in the same way.
Help me do it right, otherwise I did it once and for some reason it started up a bunch of times for me, as a result, the computer hung.
The last code was:

@echo off
chcp 1251
set ProcessName="avr.exe"
cls
TaskList /FI "ImageName EQ % ProcessName % " | Find /I %ProcessName%>nul||(
ping localhost -w 3000 > nul
start C:\Users\Asus\source\repos\avr\avr\bin\Debug\avr.exe
)

This is a baht, but when I ran it in the program, it stupidly opened a hundred times and the computer hung.
Help)0

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
MrDywar Pichugin, 2019-10-20
@SaddledSharp

1) Make it a service, with autostart.
2) Make two processes that look at each other and, if necessary, "raise" (this was used in the attack on nuclear power plants, Mark Russinovich cleared this matter with his utilities on the report). In order not to run more copies than necessary, you can use the kernel synchronization object (this is a couple of lines in C #).
Here is a time-tagged video with Mark - https://youtu.be/bNJ3HR6Z0v8?t=1964
Oh, I noticed that you are fond of information security, I've been spinning there for about a year, I've seen so much that I'm afraid to go online :) I
recommend contacting with the guys from Pentestit, there is a chat there.

R
res2001, 2019-10-21
@res2001

In general, the logic seems to be correct.
Make sure in the console that the commands are:
correctly work when the process is running and when the process is not.
By the way, in your tasklist, the percent signs framing ProcessName are written with a space. They need to be written together. Perhaps this is the reason for the error:% ProcessName %

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question