C#C
C#5mo ago
Log

✅ Exe file killer

Hello I am in need of a LOT of help. I wanna create a .cs file and turn it into .exe that kills other .exe files (for me roblox specifically (my nephews keep using my pc without permission so here I am)). I am a beginner and have very scarce knowledge about C# and/or any programming language for that matter.

Here's what I have and yes I ran this through chatgpt and some help with a few friends.
using System;
using System.Diagnostics;
using System.Threading;
namespace ConsoleApp1
{
    class Testing
    {
        static void Main()
        {
            string targetProcessName = "Roblox";
            TimeSpan maxRuntime = TimeSpan.FromMinutes(2);

            Console.WriteLine(string.Format("Monitoring process '{0}'... Will terminate it after {1} minutes.", targetProcessName, maxRuntime.TotalMinutes));

            while (true)
            {
                var processes = Process.GetProcessesByName(targetProcessName);

                if (processes.Length > 0)
                {
                    foreach (var process in processes)
                    {
                        try
                        {
                            DateTime startTime = process.StartTime;
                            Console.WriteLine(string.Format("Detected '{0}' (PID: {1}) at {2}.", process.ProcessName, process.Id, startTime));

                            while (!process.HasExited)
                            {
                                TimeSpan runtime = DateTime.Now - startTime;

                                if (runtime > maxRuntime)
                                {
                                    Console.WriteLine(string.Format("Killing {0} after {1:F2} minutes.", process.ProcessName, runtime.TotalMinutes));
                                    process.Kill();
                                    break;
                                }

                                Thread.Sleep(1000);
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(string.Format("Error: {0}", ex.Message));
                        }
                    }
                }

                Thread.Sleep(3000);
            }
        }
    }
}


whenever I try to turn it into .exe I get different errors. $ is not recognized so I used string.format and whenever
using System;
using System.Diagnostics;
using System.Threading;

is removed and turned into
using System.Diagnostics;

I get the following errors
image.png
Was this page helpful?