Asp. NET programming kills the process

Source: Internet
Author: User
Asp.net| Programming | Process through asp.net can kill some useless processes remotely, the following code lists all the processes that are active before killing. Note that this file should be placed under a virtual directory with administrator access rights.
The following is the C # code:

<%@ 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" Do you really want to kill this process?) ');");
}

private void KillProcess (string processname) {
System.Diagnostics.Process myproc= new System.Diagnostics.Process ();
Get all the open processes
try{
foreach (Process thisproc in Process.getprocessesbyname (processname)) {
if (!thisproc. CloseMainWindow ()) {
Thisproc. Kill ();
}
}
}
catch (Exception exc)
{
Msg. text+= "Kill" +procname. Selecteditem.text + "Failed!" ";
}
}
public void Btnkill_click (object sender, System.EventArgs e)
{
KillProcess (procname. Selecteditem.text);
Msg. Text= procname. Selecteditem.text + "has been killed. ";
}


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><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>
Process name </TD></TR>
<TR><TD>
<asp:button id= "Btnkill" text= "Kill Process" runat= "server" causesvalidation= "False" onclick= "Btnkill_click"/>
</TD>
<td><asp:button id= "btnshow" text= "List all Processes" runat= "server" causesvalidation= "False" onclick= "Btnshow_click" />
</TD></TR>
</TABLE>
<center><asp:label id= "MSG" runat= "Server"/></center>
</form>
</center>
</body>
</HTML>


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.