Excel进程关闭的疑惑。 http://dotnet.aspx.cc/ShowDetail.aspx?id=299D1529-59A3-42F9-77A7-7BF353754FEA 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 拒绝访问。 说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.ComponentModel.Win32Exception: 拒绝访问。源错误: 行 36: int begpos;行 37: int endpos;行 38: foreach (Process thisProc in System.Diagnostics.Process.GetProcesses()) {行 39: tempName=thisProc.ToString();行 40: begpos = tempName.IndexOf("(")+1; http://community.csdn.net/Expert/topic/3347/3347007.xml?temp=.7992517 private void KillProcess(string processName){System.Diagnostics.Process myproc= new System.Diagnostics.Process();//得到所有打开的进程 try{ foreach (Process thisproc in Process.GetProcessesByName(processName)) { if(!thisproc.CloseMainWindow()){ thisproc.Kill(); } } } catch(Exception Exc) { msg.Text+= "杀死" + processName + "失败!"; }} 这个不太好释放干净,主要看finally里面的写法Excel.Application excel = null;Excel.Workbooks wbs = null;Excel.Workbook wb = null;Excel.Worksheet ws = null;Excel.Range range1 = null;object Nothing = System.Reflection.Missing.Value; try{...}finally{ if (excel != null) { if (wbs != null) { if (wb != null) { if (ws != null) { if (range1 != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(range1); range1 = null; } System.Runtime.InteropServices.Marshal.ReleaseComObject(ws); ws = null; } wb.Close(false,Nothing,Nothing); System.Runtime.InteropServices.Marshal.ReleaseComObject(wb); wb = null; } wbs.Close(); System.Runtime.InteropServices.Marshal.ReleaseComObject(wbs); wbs = null; } excel.Application.Workbooks.Close(); excel.Quit(); System.Runtime.InteropServices.Marshal.ReleaseComObject(excel); excel = null; GC.Collect(); }} 或者直接KILL掉Excel的进程protected void KillExcel(){ foreach(Process process in System.Diagnostics.Process.GetProcesses()) { if (process.ProcessName.ToUpper().Equals("EXCEL")) process.Kill(); }} 我不知道你们是不是有试过进程强行杀死,结果将是我上面贴的错误,“拒绝访问”有人说对ASPNET用户赋予administrators权限,这样做我能放心么?我还没有试行不行,但这一定不是解决方法。有没有人再帮帮我。 如何把文件放到一个exe中 请教c#的加法运算顺序 C# C/S程序如何上传一个文件到网站服务器上 C#WINFORM添加数据时的奇怪现象?? [新手提问]20分问个小问题,要求效率最高的答案 关于两个时钟的时间联动的问题,有谁会写代码? 关于DataGridView里的ComboBox的难题(高分求解) modbus tcp 怎么编码解码,最好给出例子,谢谢 C#数据绑定中的多个问题。 C#中的类型转换问题· 哦哦 请问 assembly 是什么东东?
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.ComponentModel.Win32Exception: 拒绝访问。源错误:
行 36: int begpos;
行 37: int endpos;
行 38: foreach (Process thisProc in System.Diagnostics.Process.GetProcesses()) {
行 39: tempName=thisProc.ToString();
行 40: begpos = tempName.IndexOf("(")+1;
{
System.Diagnostics.Process myproc= new System.Diagnostics.Process();
//得到所有打开的进程
try{
foreach (Process thisproc in Process.GetProcessesByName(processName)) {
if(!thisproc.CloseMainWindow()){
thisproc.Kill();
}
}
}
catch(Exception Exc)
{
msg.Text+= "杀死" + processName + "失败!";
}
}
Excel.Application excel = null;
Excel.Workbooks wbs = null;
Excel.Workbook wb = null;
Excel.Worksheet ws = null;
Excel.Range range1 = null;
object Nothing = System.Reflection.Missing.Value;
try
{
...
}
finally
{
if (excel != null)
{
if (wbs != null)
{
if (wb != null)
{
if (ws != null)
{
if (range1 != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(range1);
range1 = null;
}
System.Runtime.InteropServices.Marshal.ReleaseComObject(ws);
ws = null;
}
wb.Close(false,Nothing,Nothing);
System.Runtime.InteropServices.Marshal.ReleaseComObject(wb);
wb = null;
}
wbs.Close();
System.Runtime.InteropServices.Marshal.ReleaseComObject(wbs);
wbs = null;
}
excel.Application.Workbooks.Close();
excel.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(excel);
excel = null;
GC.Collect();
}
}
protected void KillExcel()
{
foreach(Process process in System.Diagnostics.Process.GetProcesses())
{
if (process.ProcessName.ToUpper().Equals("EXCEL"))
process.Kill(); }
}