无法杀死C#中的进程?

我目前正在开发一个程序,该程序可以将Lua脚本注入Roblox(是的,我知道),到目前为止,除kill进程外,其他一切都运行良好。 由于Roblox是一个单一进程,因此我不需要杀死树。我已经对该主题进行了一些研究,但没有一个起作用。

Roblox runs as a process called RobloxPlayer.exe, I believe that the Process.GetProcessesByName should fetch the process via the name of it. Being Roblox, not RobloxPlayer.exe

Process[] processes = Process.GetProcessesByName("Roblox");
        foreach (Process process in processes)
        {
            process.Kill();
            process.WaitForExit();
        }
评论
  • qq网名
    qq网名 回复

    您可以对所有进程进行字符串匹配,并终止与您的条件匹配的任何进程。

    String findThisProcess = "Roblox";
    
    foreach (Process process in Process.GetProcesses()) //provides you with a list of all running processes
    {
        try
        {           
            if (process.ProcessName.Contains(findThisProcess))
            {
                Console.WriteLine("App: {0}, Name: {1}", Path.GetFileName(process.MainModule.FileName), process.ProcessName);
                process.Kill();
                process.WaitForExit();
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine("Error: " + ex);
        }
    }