欢迎来到飞鸟慕鱼博客,开始您的技术之旅!
当前位置: 首页知识笔记正文

编程杀死进程在ASP.NET

墨初 知识笔记 113阅读

Can kill some useless processes remotely through ASP. Net. The following code first lists all active processes and then kills them. It should be noted that this file should be placed in a virtual directory with administrator access. The following is the C# code:% @ pagelanguage=' c #'% htmlhead% @ importnamespace=' system. Diagnosis% scriptlanguage=' c #' runat=' server GBA (0,0,0, 1)' ' debug=' true ' void page _ Load(object sender,EventArgse){btnKill。 Attributes.Add('onclick'' javascript:returnconfirm ('Do you really want to kill this process? ');' ); } privatevidkillprocess(string process name){ System。 Processmyproc=newSystem。 diagnostics . Process();

tyle="color: rgba(0, 128, 0, 1)">//得到所有打开的进程
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>

标签:
声明:无特别说明,转载请标明本文来源!