小弟在一个项目中将数据导出为EXCEL文件,并调用KillSpecialExcel方法关闭EXCEL进程,但总是报如下错误:access is denied,小弟的项目是部署到IIS6.0中的,在项目中直接运行是可以关闭的,在IIS下却老是报上面的错误,在网上也找不到相关的资料,我怀疑是权限问题,但该添加的账户我都添加了,还是不行,不知道是什么问题,请各位高手指教,谢谢!附KillSpecialExcel方法:
[DllImport("user32.dll", SetLastError = true)]
static extern int GetWindowThreadProcessId(IntPtr hWnd, out int lpdwProcessId); public void KillSpecialExcel(Microsoft.Office.Interop.Excel.Application m_objExcel)
{
try
{
if (m_objExcel != null)
{
int lpdwProcessId;
GetWindowThreadProcessId(new IntPtr(m_objExcel.Hwnd), out lpdwProcessId); System.Diagnostics.Process.GetProcessById(lpdwProcessId).Kill();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
[DllImport("user32.dll", SetLastError = true)]
static extern int GetWindowThreadProcessId(IntPtr hWnd, out int lpdwProcessId); public void KillSpecialExcel(Microsoft.Office.Interop.Excel.Application m_objExcel)
{
try
{
if (m_objExcel != null)
{
int lpdwProcessId;
GetWindowThreadProcessId(new IntPtr(m_objExcel.Hwnd), out lpdwProcessId); System.Diagnostics.Process.GetProcessById(lpdwProcessId).Kill();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
xlApp.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(ws);
System.Runtime.InteropServices.Marshal.ReleaseComObject(wb);
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp);
xlApp = null;
wb = null;
ws = null;
System.Diagnostics.Process myproc= new System.Diagnostics.Process();
foreach (Process thisproc in Process.GetProcessesByName(processName)) {
if(!thisproc.CloseMainWindow()){
thisproc.Kill();
}}
xBk.Close(false, null, null); excel.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(xBk);
System.Runtime.InteropServices.Marshal.ReleaseComObject(excel);
System.Runtime.InteropServices.Marshal.ReleaseComObject(xSt);
xBk = null;
excel = null;
xSt = null;
GC.Collect();
这位大侠,怎么设置应用程序池用administrastor运行?我没试过,不会啊,能否说详细一点!
把用户改为administrator