-2

First of all, i tried to read other solutions for the same problem, but due my limited knowledge i was unable to make it work.

What I'm trying to make is a function that forcefully kills every process named notepad.exe using C#.

But I don't want it to kill or try to kill other users processes as well.

If it could perform as same as this taskill cmd command, it would be great!

taskkill /fi "username eq %username%" /im notepad.exe /f

So far i was only able to do this, that partially solves the problem, but will other users processes :

private void KillNotepad()
            {
                var procs = Process.GetProcessesByName("notepad");
                foreach (var proc in procs)
                {
                    proc.Kill();
                }
            }
jagarop
  • 1
  • 1
  • Sadly there is no .user or similar property on process, you'll need to query it yourself using one of the methods you can find in this question : https://stackoverflow.com/questions/777548/how-do-i-determine-the-owner-of-a-process-in-c – Ronan Thibaudau May 30 '22 at 17:16
  • @jagarop You could use the `Process` class to open and feed in the specific arguments like you listed above to the command line. This would effectively do the same thing but without user input. [passing-an-argument-to-cmd-exe](https://stackoverflow.com/questions/5047171/passing-an-argument-to-cmd-exe) – Ryan Wilson May 30 '22 at 17:22

0 Answers0