当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > ASP.NET中编程杀死进程

ASP.NET
漫谈.Net开发关于命名空间和目录划分
.net中关于企业Excel报表的生成
.NET中取得IP/用户名等信息常用方法
关于.Net开发下的分布式缓存设计
.NET中为组合框添加自动查询功能
ASP.NET如何进行性能优化问题
开发中如何有效监控.NET应用程序
ASP.NET2.0 显示写入日期和时间语法
用.NET Array类的Sort方法分类数值
Asp.net Mvc Pv4中使用AjaxHelper
Asp.net中Forms验证的角色验证授权(一)
Asp.net中Forms验证的角色验证授权(二)
Asp.Net2.0数据库基本操作方法学习
Asp.Net之枚举类型输出需要类型转换
用.NET的File控件上传文件的解决方案
.NET泛型技巧之类型参数之间的转换
在ASP.NET中将数据直接输出成Excel格式
在.NET框架下使用自定义配置设置
跟ASP.NET MVC一起使用jQuery
Visual Basic中文本框处理技巧集萃

ASP.NET中编程杀死进程


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 88 ::
收藏到网摘: n/a

通过ASP.NET可以对一些无用的进程进行远程杀死,下面的代码先列出正在活动的所有进程,然后进行杀死。需要注意的是:这个文件要放在具有Administrator访问权限的虚拟目录下。

以下是C#代码:

<%@PageLanguage="c#"%>
<HTML>
<HEAD>
<%@Importnamespace="System.Diagnostics"%>
<scriptlanguage="C#"runat="Server"debug="true">
voidPage_Load(ObjectSender,EventArgse){
btnKill.Attributes.Add("onclick","javascript:returnconfirm('你真的要杀死这个进程吗?');");
}

privatevoidKillProcess(stringprocessName){
System.Diagnostics.Processmyproc=newSystem.Diagnostics.Process();
//得到所有打开的进程
try{
foreach(ProcessthisprocinProcess.GetProcessesByName(processName)){
if(!thisproc.CloseMainWindow()){
thisproc.Kill();
}
}
}
catch(ExceptionExc)
{
msg.Text+="杀死"+procname.SelectedItem.Text+"失败!";
}
}
publicvoidbtnKill_Click(objectsender,System.EventArgse)
{
KillProcess(procname.SelectedItem.Text);
msg.Text=procname.SelectedItem.Text+"已经被杀死。";
}


publicvoidbtnShow_Click(objectsender,System.EventArgse){
ArrayListprocList=newArrayList();
stringtempName="";
intbegpos;
intendpos;
foreach(ProcessthisProcinSystem.Diagnostics.Process.GetProcesses()){
tempName=thisProc.ToString();
begpos=tempName.IndexOf("(")+1;
endpos=tempName.IndexOf(")");
tempName=tempName.Substring(begpos,endpos-begpos);
procList.Add(tempName);
}
procname.DataSource=procList;
procname.DataBind();
}
</script>
</HEAD>
<body>
<BasefontFace="Tahoma"/>
<center><h2>ASP.NET进程杀死器!</h2><BR>
<Tablecellspacing=2cellpadding=2border=0BGCOLOR="#fFCC66">
<formid="frmProc"runat="Server"method="post">
<TR><TD><ASP:DropDownListid="procname"runat="server"/></TD><TD>
进程名字</TD></TR>
<TR><TD>
<asp:buttonid="btnKill"Text="杀死进程"runat="server"CausesValidation="False"onclick="btnKill_Click"/>
</TD>
<TD><asp:buttonid="btnShow"Text="列出所有进程"runat="server"CausesValidation="False"onclick="btnShow_Click"/>
</TD></TR>
</TABLE>
<center><asp:Labelid="msg"runat="server"/></center>
</form>
</center>
</body>
</HTML>