Win32Exception (0x80004005): 拒绝访问。
ASP.Net + C# + SQLServer 2005 + IIS 5.1 服务器环境 XP SP3
在我自己的笔记本环境中调试都是好的,到服务器上部署就出问题了,在网上查了一整天的解决方案,大致问题所在也了解了,应该是杀进程的时候权限不够,但郁闷的是网上所有的解决方案都试过了还是没用。
报错部分代码:
[DllImport("User32.dll" , CharSet = CharSet.Auto)]
private static extern int GetWindowThreadProcessId(IntPtr hwnd , out int ID);
//End the process of xlApp
public void KillExcelProcess()
{
//get the hwnd(t) of excel, it is the entrance of memory used by excel
IntPtr t = new IntPtr(xlApp.Hwnd);
int k = 0;
//get the id(k) of process by hwnd(t)
GetWindowThreadProcessId(t , out k);
//get the reference of process(p) by id(k)
Process p = Process.GetProcessById(k);
//kill the process
p.Kill();
}
public void KillExcelProcess2(string fileName)
{
Process[] procList = Process.GetProcesses();
IntPtr t = new IntPtr(xlApp.Hwnd);
int k = 0;
//get the id(k) of process by hwnd(t)
GetWindowThreadProcessId(t, out k);
foreach (Process proc in procList)
{
if (k == proc.Id)
proc.Kill();
}
}