获取Excel应用程序进程id [英] Getting excel application process id
本文介绍了获取Excel应用程序进程id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建用C#Excel应用程序。
由于我将保持在紧急Excel文件我要保持它的处理程序打开。
我想保持Excel进程ID,这样我就能杀死它,以防系统crashs。
我怎样才能创建时获得的Excel的Pid它
解决方案
使用Excel =的Microsoft.Office.Interop.Excel?;使用System.Runtime.InteropServices
;使用System.Diagnostics程序
;
类样品
{
函数[DllImport(user32.dll中)]
静态外部INT GetWindowThreadProcessId(INT的HWND,OUT INT lpdwProcessId);
过程GetExcelProcess(Excel.Application excelApp)
{
INT ID;
GetWindowThreadProcessId(excelApp.Hwnd,掉id);
返回Process.GetProcessById(ID);
}
}
I am creating an excel application with c#. Since I will maintain the excel file in urgency I want to keep its handler open. I want to keep the excel process id so I will be able to kill it in case the system crashs.
How can I get the Excel Pid when creating it?
解决方案
using Excel = Microsoft.Office.Interop.Excel;
using System.Runtime.InteropServices;
using System.Diagnostics;
class Sample
{
[DllImport("user32.dll")]
static extern int GetWindowThreadProcessId(int hWnd, out int lpdwProcessId);
Process GetExcelProcess(Excel.Application excelApp)
{
int id;
GetWindowThreadProcessId(excelApp.Hwnd, out id);
return Process.GetProcessById(id);
}
}
这篇关于获取Excel应用程序进程id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文