我想在我的exe运行时禁用操作系统中的进程。如果在我的进程启动时运行的前进程将被禁用,并且在我的exe关闭后它将继续运行。
我正在使用C#,我在process.kill
命名空间中尝试了System.Diagnostics
方法,但该函数永久关闭了应用程序。
答案 0 :(得分:0)
Process A;
Process B;
Process C;
private void findExes()
{
List<Process> allProcesses = Process.GetProcesses().ToList().OrderBy(p => p.ProcessName).ToList();
A = allProcesses.Find(delegate(Process pro) { return pro.ProcessName == "A"; });
B = allProcesses.Find(delegate(Process pro) { return pro.ProcessName == "B"; });
C = allProcesses.Find(delegate(Process pro) { return pro.ProcessName == "C"; });
}
private void stopAExe_Click(object sender, EventArgs e)
{
findExes();
if (A != null)
A.Kill();
if ( B != null)
{
/// RESUME B.EXE
/// B.EXE WİLL CONTİNUE
}
}
private void startAExe_Click(object sender, EventArgs e)
{
findExes();
if (A == null)
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = @"A.exe";
Process.Start(startInfo);
if (B != null)
{
///
/// DİSABLE B.EXE ?
}
}
}
private void startBExe_Click(object sender, EventArgs e)
{
findExes();
if ( B == null)
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = @"B.exe";
Process.Start(startInfo);
}
}