Process Checker [Answered]
I'm creating an ""antivirus"" and I'm using a thread to check when a new process is started (but the thread is consuming a lot of cpu and I was wondering if there is another way to do this)
15 Replies
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
@Peep i'm checking every certain time if the process (I'll give an example) notepad.exe was executed if it was it terminates the process
however this demands a lot of CPU and I don't know another effective way or that doesn't spend so much cpu
share some code as you may be able to do it in a more efficient way
@Anchy the code looks like this
You need to Dispose all other processes in the array that you don't use
The app would always be CPU heavy because your loop is running every 5ms
@Kouhai yes it is running every 5ms just so the application can't even run (but I don't know any other way to do this without using a thread)
Unfortunately querying all running proceses is an expensive operation
If you're actually interested in how anti viruses work, they essentially get notified when a new process starts instead of looping and checking every process
@Kouhai OK. but how can I be ""notified""
You can take a look at WMI, though a real anti virus would have a custom driver instead of using WMI
okay, I'll look
Stack Overflow
Is there a System event when processes are created?
Is there any event when a new process is created. I'm writing a c# application that checks for certain processes, but I don't want to write an infinite loop to iterate through all known processes
For the WMI approach.
Ok thanks
✅ This post has been marked as answered!