• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
内蒙古峰回路转armyfeng
博客园    首页    新随笔    联系   管理    订阅  订阅

ASP.NET 进程杀死器

<%@ Page Language="c#" %>

<html>
<head>
<title>ASP.NET 进程杀死器</title>
    
<% @ Import namespace= "System.Diagnostics" %>

    
<script language="C#" runat="Server" debug="true">
void Page_Load(Object Sender, EventArgs e){
    btnKill.Attributes.Add(
"onclick", "javascript: 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>
    
<form id="frmProc" runat="Server" method="post">
        
<basefont face="Tahoma" />
        
<center>
            
<h2>
                ASP.NET 进程杀死器!
</h2>
            
<br>
            
<table cellspacing="2" cellpadding="2" border="0" bgcolor="#fFCC66">
                
<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>
        
</center>
    
</form>
</body>
</html>
posted @ 2007-02-09 17:18  老冯  阅读(181)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3