[英]How can i send close command to a CMD process by PID
This process is started by selenium 这个过程由硒开始
So i do not have control over it how i start it 所以我无法控制它是如何开始的
However, the CMD process have X button 但是,CMD进程有X按钮
Can i programmatically call that X button by PID? 我可以通过PID以编程方式调用该X按钮吗?
C# 4.6.2 windows 8.1 C#4.6.2 windows 8.1
I am able to kill the process however it is not making the same effect as X button click 我能够杀死该过程,但它没有与X按钮点击产生相同的效果
This is part of my code using system command taskkill: 这是使用系统命令taskkill的代码的一部分:
//starts a command
public static int RunCommandAndWait(string command, string args)
{
int result = -1;
Process p = new Process();
p.StartInfo.Arguments = args;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.FileName = command;
p.StartInfo.UseShellExecute = true;
if (p.Start())
{
p.WaitForExit();
result = p.ExitCode;
}
p.Dispose();
return result;
}
//kills a process using its pid and above method
public static void KillProcessTree(int processId)
{
RunCommandAndWait("taskkill", String.Format("/pid {0} /f /t", processId));
try
{
Process p = Process.GetProcessById(processId);
if (p != null)
KillProcessTree(processId); //this sometimes may be needed
}catch(Exception)
{
}
}
This should do the trick: 这应该做的伎俩:
// Close process by sending a close message to its main window.
myProcess.CloseMainWindow();
// Free resources associated with process.
myProcess.Close();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.