zoukankan      html  css  js  c++  java
  • 在ASP.NET中杀死进程

    <%@ 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", "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> <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>  
  • 相关阅读:
    module.exports 和 exports的区别
    nodejs概述和理解
    sass的继承,混合宏,占位符的用法总结
    项目发布方式
    扩展运算符和解构赋值的理解
    C3----几个常用的加载图标制作
    gulp和yarn打包工具二分钟包会教程(高阶)
    Java接口
    Tomcat8 连接池
    DAMA
  • 原文地址:https://www.cnblogs.com/chenzhao/p/2081927.html
Copyright © 2011-2022 走看看