. NET deployment IIS cannot kill Excel process on server

Source: Internet
Author: User
Tags null null

[Win32Exception (0x80004005): Access denied. ]   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

Above is stack information cannot kill Excel process because of insufficient permissions

Modify identity in a thread pool

Modify to administrative permissions to close the process

You can do it with a collector.

NULL NULL NULL; Gc. Collect ();

The kill process is a good way to test it locally.

[DllImport ("User32.dll", CharSet =CharSet.Auto)] Public Static extern intGetWindowThreadProcessId (INTPTR hwnd, out intID);  Public  voidKill (Microsoft.Office.Interop.Excel.Application Excel) {IntPtr T=NewIntPtr (Excel. Hwnd);//to get this handle, the specific function is to get this memory entry            intK =0; GetWindowThreadProcessId (T, outk);//get the unique mark of this process KSystem.Diagnostics.Process p = System.Diagnostics.Process.GetProcessById (k);//get a reference to process KP.kill ();//Close Process K        } 

No prompt on the server

Win32Exception (0x80004005): Access Denied

So it's perfectly feasible to test it in GC.

. NET deployment IIS cannot kill Excel process on server

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.