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

ASP.NET
Active Directory 对象的控制
在vb中动态加载水晶报表rpt文件的方法
webconfig中进行登陆的权限、修改2
DataGrid(WinForm)显示行号最简单的方法
在EXCEL中获取列中不重复的值的个数
使用Visual C#制作可伸缩个性化窗体
关于控件注册和使用许可问题的解决办法
获取闭合符号中的字符串
判断点与多边形的状态(位置)
NHibernate初试
GetTickCount()函数精确到多少毫秒
VB.net中HOOK的应用(一)
C# to VB.Net translator..
用Visual C#调用Windows API函数
用API函数实现切换VCD的左右声道
元数据--自定义属性(VB.NET)
初学VB.NET连接SQL数据库
简单的DataGrid多表头制作方法
带输出参数的存储过程的使用及在C#中调用问题
VS的控件真是不好用,好不容易才搞定DataGrid

ASP.NET中编程杀死进程


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 95 ::
收藏到网摘: 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>