您的位置:首页 > 编程语言 > C#

C# 关闭EXCEL进程

2010-06-29 11:39 309 查看
[DllImport("User32.dll", CharSet = CharSet.Auto)]
public static extern int GetWindowThreadProcessId(IntPtr hwnd, out int ID);
private void Kill(Application theApp)
{
if (theApp == null)
{
return;
}

int iId = 0;
IntPtr intptr = new IntPtr(theApp.Hwnd);
System.Diagnostics.Process p = null;

try
{
GetWindowThreadProcessId(intptr, out iId);
p = System.Diagnostics.Process.GetProcessById(iId);

if (p != null)
{
p.Kill();
p.Dispose();
}
}
catch (Exception e)
{
throw e;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: