日期:2014-05-20 浏览次数:21112 次
Process[] process = Process.GetProcesses(); foreach (Process prc in process) { Console.WriteLine(prc.ProcessName); if (prc.ProcessName == "Excel") prc.Kill(); } Console.ReadLine();
------解决方案--------------------
private void KillProcess(string processName)
{
System.Diagnostics.Process myproc= new System.Diagnostics.Process();
foreach (Process thisproc in Process.GetProcessesByName(processName)) {
if(!thisproc.CloseMainWindow()){
thisproc.Kill();
GC.Collect();
}
Process[] prcs = Process.GetProcesses();
foreach (Process p in prcs) {
if (p.ProcessName.Equals("程序名")) {
p.Kill();
}
}
------解决方案--------------------
private void MainFrm_FormClosing(object sender, FormClosingEventArgs e)
{
if (MessageBox.Show("确定退出吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
{
// notifyIcon1.Visible = false;
System.Diagnostics.Process[] myProcesses = System.Diagnostics.Process.GetProcesses();
foreach (System.Diagnostics.Process myProcess in myProcesses)
{
if ("stock" == myProcess.ProcessName)
myProcess.Kill();
}
}
else
{
MainFrm app = new MainFrm();
app.Show();
}
}
------解决方案--------------------
lz,我帖子的意思是你不要按Process.ProcessName去杀进程.
你看一下Process类,其中有很多地方标记了该Process的信息的.
比如
Process.MainModule中的多项属性
Process.MainWindowTitle
等
根据这些信息肯定可以定位到你在进程内创建到窗体上的Word