Click here to Skip to main content
15,886,036 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm making a program that when it's in enabled mode, then the user is watching adult content or something he wants to hide from others, so if a kid enters the home and he isn't supposed to see what's on the screen, when the adult pressed "RightCtrl" a browser he uses for this only gets terminated instantly, all of its instances (multiple windows and multiple tabs), the user enters the name of the process of the browser or chooses as I put a combobox and he chooses the name of the browser from a list of browsers, and I would find the name of the process and enter it in my program, but I want to kill *all* the instances of that browser immediately, what does "kill process tree" mean and can it be useful here plz?

How do you recommend I see the exact names of the process of the browser? start them one by one and check task manager plz?

What I have tried:

C#
try
{Process[] workers = Process.GetProcessesByName("nameOfBrowserHere")
foreach (Process worker in workers)
{
     worker.Kill();
     worker.WaitForExit();
     worker.Dispose();
}
}
catch {}

Maybe this is better:

C#
foreach(Process p in Process.GetProcessesByName("nameOfBrowserHere")) p.Kill();
Posted
Updated 5-May-22 2:14am
v4
Comments
Richard MacCutchan 4-May-22 10:52am    
Or the adult can stop behaving like a child. Or even (shock horror) click the X in the top right corner.
FierceLion 4-May-22 10:54am    
It's a program I want to make for everyone, also with the ability to type any process name maybe for other programs, it's easy to make and useful to be around and I enjoy programming useful stuf, I'm not behaving like a child I need this for good stuff too.
Richard MacCutchan 4-May-22 10:59am    
I said "the adult" behaving like a child, i.e. viewing inappropriate content. And by the time he has figured out what to type into your program the kid will have seen everything.
FierceLion 4-May-22 11:00am    
The user chooses the name of the browser and whenever he hears a kid coming around the adult simply presses "RightControl" and on key down the browser would be killed!
Richard MacCutchan 4-May-22 11:03am    
Do you know what happens if you press that (or any) key combination while the browser has the focus?

That's not simple, at all. The real problem is detecting the keypress "in any app" - which you would have to do in case he is watching the browser and the focus is elsewhere, and definitely have to do if he can define which app to close.
That's possible, but it requires a Global Hook - which is not easy to arrange in C#, and if you decide to do it you'd probably best backup your computer each day before you start testing your code - if you get a hook wrong, it can have catastrophic results.

And it isn't even necessary in Win 10 / Win 11: WINKEY, CTRL + D create a new empty desktop, and WINKEY, CTRL + LEFT / WINKEY, CTRL + RIGHT switches between them.
So "hiding inappropriate material" from your child or boss is available already.

But the best solution is simpler than that: don't watch inappropriate material in a location that may be overlooked.
 
Share this answer
 
Comments
FierceLion 4-May-22 11:17am    
I have global keyboard hooks, and if the user presses "Win+D" the video would still make sound, I noticed this program and I'm not doing it for me to watch porn, I'm not a bad person, I use it for good things, I think the code works, I just thought there's something about: "kill process tree" that I saw in task manager, that can help me, no need to say I'm a bad person, I will check if my code kills all windows of a browser or another program which can be useful for other stuff too!!!
I think you've answered your own question:
How do you recommend I see the exact names of the process of the browser? start them one by one and check task manager plz?

Each browser will have an executable that will need to run on the machine at least once. For example, Google Chrome depends on a chrome.exe, which then spawns new instances of the same process for each tab. All you can do really is either install and check the shortcut paths for each browser to see what the process name will be, or just Google each browser and hopefully their websites might give you that information.

Alternatively if you're providing a UI with the application, you could have them choose the name of the process to hide, though I doubt that will be a very user-friendly experience.

Also what happened to good ol' fashioned Alt + Tab or Win + D?
 
Share this answer
 
Comments
FierceLion 5-May-22 8:15am    
Thx, for example Chrome and Chromium and Cent browser all share the same process name "chrome", should I make a dropdown list with the number (ID) of the process? is it the same for everyone?
Dave Kreskowiak 5-May-22 13:49pm    
What you see in Task Manager -> Details is the "image name", or the name of the executable that's launched.

ProcessID's are random and assigned when a process is launched. They are not the same on every machine, nor even when you launch the same process again and again on the same machine.
FierceLion 5-May-22 14:01pm    
Thx, how can I kill Chrome without killing Chromium? kill Opera without killing OperaGX? they share the same process name "chrome" and "opera" respectively.
Dave Kreskowiak 5-May-22 14:02pm    
You can't! There is no way for your code to determine which process is which browser since they all use the same name.
FierceLion 5-May-22 16:46pm    
Are you sure or should I ask in a new question as maybe there's a way for my program to know to kill for example only Chrome and not Chromium with it?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900