📄 killapplication.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Diagnostics;
namespace Example_12_19
{
/// <summary>
/// KillApplication 的摘要说明。
/// </summary>
public class KillApplication : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList procname;
protected System.Web.UI.WebControls.Button btnKill;
protected System.Web.UI.WebControls.Button btnShow;
protected System.Web.UI.WebControls.Label msg;
protected System.Web.UI.HtmlControls.HtmlForm frmProc;
private 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();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.btnKill.Click += new System.EventHandler(this.btnKill_Click);
this.btnShow.Click += new System.EventHandler(this.btnShow_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -