Way to stop a program from starting up using c#?

Here is the suggestion, I would certainly such as to make a service? that will certainly seek a particular program launching and also dissallow it unless particular problems are fulfilled.

Allow is claim I have a video game I intend to stop myself from playing throughout the week. So if I start it up on any kind of day apart from Friday/Saturday/Sunday, it will certainly obstruct and also terminate. Is this feasible with C#?

Important things I am seeking is just how to capture a program launching, remainder needs to be very easy.

2022-07-25 20:41:14
Source Share
Answers: 3

Well, you can definitely determine which programs are running by looking for the process names you want (GetProcessesByName()) and killing them.

Process[] processes = Process.GetProcessesByName(processName);
foreach(Process process in processes)

You could just have a list of them you didn't want to run, do the time check (or whatever criteria was to be met) and then walk the list. I did something like this once for a test and it works well enough.

2022-07-25 21:45:06

I do not find out about C# specifically below yet one why you can complete this (I'll be it is an unsafe means) is by utilizing the Image File Execution Options () in the computer system registry. For whatever executable you want obstructing you can set the Debugger alternative for it and afterwards create a tiny application that would certainly be made use of at the debugger after that have it basically filter these telephone calls. If you intended to permit it to run after that start up the procedure or else do whatever you such as. I' ve never ever tried this yet it feels like it can do what you desire.

Or if you intended to respond to the procedure launching and afterwards close it down you can make use of a ProcessWatcher () and also register for the procedure developed occasion and afterwards close it down if required. Nonetheless that is even more of responsive strategy rather an aggressive strategy like the first one.

2022-07-25 21:45:03

There is constantly hooks. Although there is no assistance for it in the.net collection you can constantly cover the win32 dll. Below is a wonderful write-up:

This is reduced - degree shows, and also if you desire your code to be mobile i would not make use of hooks.

2022-07-25 21:44:59