我尝试使用DebugActiveProcess挂起进程,但结果未返回true且无法附加到进程。我怎样才能使它可行?
string processName = "notepad";
System.Threading.Thread.Sleep(1000);
Process[] processes = Process.GetProcessesByName(processName);
if (processes.Length > 0)
{
int processId = processes[0].Id;
Console.WriteLine("Process ID: " + processId);
// Get the process ID of the process you want to suspend
// Attach to the process and suspend it
bool result = DebugActiveProcess(processId);
if (result == false)
{
Console.WriteLine("Failed to attach to process");
return;
}
// The process is now suspended. Do your debugging tasks here.
// Detach from the process
Process process = Process.GetProcessById(processId);
process.WaitForInputIdle(); // Wait for the process to become idle
System.Threading.Thread.Sleep(1000 * 5 * 60);
DebugActiveProcessStop(processId);
}
我正在尝试使用DebugActiveProcess挂起进程
1条答案
按热度按时间au9on6nz1#
我有同样的问题,但当我创建一个新的控制台应用程序,并确保它没有其他代码,它为我工作。DebugActiveProcess返回true(成功)。
所以我将通过另一个控制台应用程序挂起一个进程,我猜有些代码不是你的,它们确实改变了你的应用程序的环境。