[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