如何获取当前word进程 并关闭
最近一直在用C#操作word 想了解一下如何在C#程序中获取当前操作的word进程 并关闭当前操作的word进程(注意:不是关闭所有的word进程)
[解决办法]
之前查到过Excel的,感觉应该差不多,是写了一个函数,参数改成你正在操作的word,可以试一下
public static void Kill(Excel.Application excel)
{
IntPtr t = new IntPtr(excel.Hwnd); //得到这个句柄,具体作用是得到这块内存入口
int k = 0;
GetWindowThreadProcessId(t, out k); //得到本进程唯一标志k
System.Diagnostics.Process p = System.Diagnostics.Process.GetProcessById(k); //得到对进程k的引用
p.Kill(); //关闭进程k
}
Worksheets sheets = excelApp.Worksheets; // <-- the important part
Worksheet sheet = sheets.Open(...);
...
Marshal.ReleaseComObject(sheets);
Marshal.ReleaseComObject(sheet);