关闭

asp.net 获取进程。。杀到进程

919人阅读 评论(0) 收藏 举报
分类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Diagnostics;
using System.Collections;

public partial class user_Exposure : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        //得到所有打开的进程
        ArrayList procList = new ArrayList();
        string tempName = "";
        int begpos;
        int endpos;
        foreach (Process thisProc in Process.GetProcesses())
        {
            tempName = thisProc.ToString();
            begpos = tempName.IndexOf("(") + 1;
            endpos = tempName.IndexOf(")");
            tempName = tempName.Substring(begpos, endpos - begpos);
            procList.Add(tempName);
        }
        DropDownListProcname.DataSource = procList;
        DropDownListProcname.DataBind();
       
    }
    private void KillProcess(string processName)
    {
        //得到所有打开的进程
        try
        {
            foreach (Process thisProc in Process.GetProcessesByName(processName))
            {
                if (!thisProc.CloseMainWindow())
                {  Button2.Text = thisProc.MainModule.FileName;
                    thisProc.Kill();
                  
                }
            }
        }
        catch
        {
          
        }
    }

    protected void Button2_Click(object sender, EventArgs e)
    {


        KillProcess(DropDownListProcname.SelectedItem.Text);
     
        
       
    }
}
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:39067次
    • 积分:831
    • 等级:
    • 排名:千里之外
    • 原创:43篇
    • 转载:4篇
    • 译文:0篇
    • 评论:6条
    文章分类