首页 新闻 赞助 找找看

System.ComponentModel.Win32Exception: 拒绝访问。

0
悬赏园豆:30 [已解决问题] 解决于 2016-01-12 16:30

拒绝访问。

说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.ComponentModel.Win32Exception: 拒绝访问。
源错误:

执行当前 Web 请求期间生成了未经处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。

堆栈跟踪:

[Win32Exception (0x80004005): 拒绝访问。]
   System.Diagnostics.ProcessManager.OpenProcess(Int32 processId, Int32 access, Boolean throwIfExited) +6539818
   System.Diagnostics.Process.GetProcessHandle(Int32 access, Boolean throwIfExited) +93
   System.Diagnostics.Process.Kill() +46
   MouldWEBKT.App_Code_old.ExcelOperate.Dispose(_Application CurExcel) +123
   MouldWEBKT.Design.BOMdr_KT.Button7_Click(Object sender, EventArgs e) +25581
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9750842
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +196
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724

 win2008 iis7  导入Excel  的时候,最后 kill 掉Excel 进程的时候报错。Excel写入都是正常的。

问题补充:

代码如下: 调用这个报错。

       [DllImport("User32.dll", CharSet = CharSet.Auto)]
        public static extern int GetWindowThreadProcessId(IntPtr hwnd, out int ID);

   public static void Dispose(Excel._Application CurExcel)
        {
            IntPtr t = new IntPtr(CurExcel.Hwnd);
            int k = 0;
            GetWindowThreadProcessId(t, out k);
            System.Diagnostics.Process p = System.Diagnostics.Process.GetProcessById(k);
            p.Kill();
        }

 

目前使用这个,还行。

                    app.Quit();
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(workbook);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(app);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(sheets);
                    app = null;
                    workbook = null;
                    sheets = null;
                    GC.Collect();

pengbg的主页 pengbg | 初学一级 | 园豆:13
提问于:2015-10-27 17:28
< >
分享
最佳答案
0

就这样吧!

pengbg | 初学一级 |园豆:13 | 2015-10-29 11:11
其他回答(2)
1

没权限吧

jello chen | 园豆:7306 (大侠五级) | 2015-10-27 18:32
0

没有权限,我记得可以使用另外一种方式,强制KILL

收获园豆:30
ta_wuhen | 园豆:271 (菜鸟二级) | 2015-12-18 11:16
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册