欢迎光临
我们一直在努力

ASP.NET中编程杀死进程-.NET教程,Asp.Net开发

建站超值云服务器,限时71元/月

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

  以下是c#代码:

<%@ page language="c#" %>

<html>

<head>

<% @ import namespace= "system.diagnostics" %>

<script language="c#" runat="server" debug="true">

void page_load(object sender, eventargs e){

btnkill.attributes.add("onclick", "java script: return confirm(你真的要杀死这个进程吗?);");

}

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+= "杀死" +procname.selecteditem.text + "失败!";

}

}

public void btnkill_click(object sender, system.eventargs e)

{

killprocess(procname.selecteditem.text);

msg.text= procname.selecteditem.text +" 已经被杀死。";

}

public void btnshow_click(object sender, system.eventargs e){

arraylist proclist =new arraylist();

string tempname="";

int begpos;

int endpos;

foreach (process thisproc in system.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>

<basefont face="tahoma" />

<center><h2>asp.net 进程杀死器!</h2><br>

<table cellspacing=2 cellpadding=2 border=0 bgcolor="#ffcc66">

<form id="frmproc" runat="server" method="post">

<tr><td><asp:dropdownlist id="procname" runat="server" /></td><td>

进程名字</td></tr>

<tr><td>

<asp:button id="btnkill" text="杀死进程" runat="server" causesvalidation="false" onclick="btnkill_click" />

</td>

<td><asp:button id="btnshow" text="列出所有进程" runat="server" causesvalidation="false" onclick="btnshow_click" />

</td></tr>

</table>

<center><asp:label id="msg" runat="server"/></center>

</form>

</center>

</body>

</html>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » ASP.NET中编程杀死进程-.NET教程,Asp.Net开发
分享到: 更多 (0)

相关推荐

  • 暂无文章