分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 技术分享

.net 部署IIS 在服务器无法杀掉EXCEL进程

发布时间:2023-09-06 01:09责任编辑:沈小雨关键词:暂无标签
[Win32Exception (0x80004005): 拒绝访问。] ??System.Diagnostics.Process.GetProcessHandle(Int32 access, Boolean throwIfExited) +1985316 ??System.Diagnostics.Process.Kill() +49 ??ApricotCMS.Controllers.ImportController.Kill(_Application excel) +144 ??ApricotCMS.Controllers.ImportController.Family(HttpPostedFileBase file) +27340 ??lambda_method(Closure , ControllerBase , Object[] ) +127 ??System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +264

  上面是堆栈信息  无法kill掉excel进程 因为权限不够

修改线程池中的Identity 

修改为管理权限就可以关闭进程了

用回收器可以搞定 

appExcel.Workbooks.Close();appExcel.Quit();System.Runtime.InteropServices.Marshal.ReleaseComObject(ws);ws = null;System.Runtime.InteropServices.Marshal.ReleaseComObject(wb);wb = null;System.Runtime.InteropServices.Marshal.ReleaseComObject(appExcel);appExcel = null;GC.Collect();

用kill进程的方法很好 在本地测试完全没问题

[DllImport("User32.dll", CharSet = CharSet.Auto)] ???????public static extern int GetWindowThreadProcessId(IntPtr hwnd, out int ID); ???????public ?void Kill(Microsoft.Office.Interop.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 ?????????} 

在服务器上就不行  提示 

Win32Exception (0x80004005): 拒绝访问

所以还是用GC回收的方式可行 测试绝对可行

.net 部署IIS 在服务器无法杀掉EXCEL进程

原文地址:http://www.cnblogs.com/seanjack/p/7478613.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved