using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace 获取当前窗口句柄
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string x = textBox1.Text;
System.Diagnostics.Process[] ps = System.Diagnostics.Process.GetProcesses();//获取所有进程
int i = ps.Length-1;
foreach (System.Diagnostics.Process p in ps)
{
i--;
if (i < 0) { MessageBox.Show("未找到程序"); }
else{
if (p.ProcessName == x)//如果是QQ播放器
{
p.Kill();
MessageBox.Show("程序已关闭");
break;
}
}
}
}
}
}