以word 进程为例子
/// <summary>
/// 杀掉所有winword.exe进程
/// </summary>
public void killAllProcess() // 杀掉所有winword.exe进程
{
System.Diagnostics.Process[] myPs;
myPs = System.Diagnostics.Process.GetProcesses();
foreach (System.Diagnostics.Process p in myPs)
{
if (p.Id != 0)
{
try
{
if (p.Modules != null)
if (p.Modules.Count > 0)
{
System.Diagnostics.ProcessModule pm = p.Modules[0];
if (pm.ModuleName.ToLower() == "winword.exe" && p.MainWindowTitle == "")
p.Kill();
}
}
catch { }
}
}
//System.Diagnostics.Process[] pss = System.Diagnostics.Process.GetProcessesByName("WINWORD.EXE", "ZY-PC");
//foreach (System.Diagnostics.Process p in myPs)
//{
// if (p.Id != 0)
// {
// string myS = "WINWORD.EXE" + p.ProcessName + " ID:" + p.Id.ToString();
// try
// {
// if (p.Modules != null)
// if (p.Modules.Count > 0)
// {
// System.Diagnostics.ProcessModule pm = p.Modules[0];
// myS += "\n Modules[0].FileName:" + pm.FileName;
// myS += "\n Modules[0].ModuleName:" + pm.ModuleName;
// myS += "\n Modules[0].FileVersionInfo:\n" + pm.FileVersionInfo.ToString();
// if (pm.ModuleName.ToLower() == "winword.exe")
// p.Kill();
// }
// }
// catch
// { }
// finally
// {
// }
// }
//}
}
如果在winform里面打开的word这个属性值是个空字符串。谢谢各位,结贴给分了。