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; using System.Diagnostics; using ConnectPoint; namespace ConnectPoint { public partial class message : Form { public static string ProcessName; [System.Runtime.InteropServices.DllImport("kernel32.dll")] public static extern int WinExec(string exeName, int operType); //调用API [System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto, ExactSpelling = true)] public static extern IntPtr GetForegroundWindow(); //获得本窗体的句柄 [System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "SetForegroundWindow")] public static extern bool SetForegroundWindow(IntPtr hWnd);//设置此窗体为活动窗体 //定义变量,句柄类型 public IntPtr Handle1; Timer timer2 = new Timer(); /// /// 弹窗参数 /// /// 标题名称 /// 内存地址 public message(string _name,string _memory) { InitializeComponent(); ProcessName = _name; this.Text = _name + ".exe - 应用程序错误"; this.label1.Text = "\""+_memory +"\"指令引用的\""+_memory+"\"内存。该内存不能为\"read\"。" ; this.label2.Text = "要终止程序,请单击\"确定\"。"; this.label3.Text = "要调试程序,请单击\"取消\"。"; this.picICO.Image= Properties.Resources.Error; } private void message_Load(object sender, EventArgs e) { Handle1 = this.Handle; timer2.Tick += new EventHandler(timer2_Tick); timer2.Interval = 2000; timer2.Start(); } private void button1_Click(object sender, EventArgs e) { try { WinExec("taskkill.exe /im "+ ProcessName + ".exe /f /t", 0); //Process[] MyProcess1 = Process.GetProcessesByName(ProcessName); //Process MyProcess = new Process(); ////设定程序名 //MyProcess.StartInfo.FileName = "cmd.exe"; ////关闭Shell的使用 //MyProcess.StartInfo.UseShellExecute = false; ////重定向标准输入 //MyProcess.StartInfo.RedirectStandardInput = true; ////重定向标准输出 //MyProcess.StartInfo.RedirectStandardOutput = true; ////重定向错误输出 //MyProcess.StartInfo.RedirectStandardError = true; ////设置不显示窗口 //MyProcess.StartInfo.CreateNoWindow = true; ////执行强制结束命令 //MyProcess.Start(); //MyProcess.StandardInput.WriteLine("ntsd -c q -p " + (MyProcess1[0].Id).ToString());//直接结束进程ID //MyProcess.StandardInput.WriteLine("Exit"); Close(); } catch { } } private void button2_Click(object sender, EventArgs e) { try { WinExec("taskkill.exe /im " + ProcessName + ".exe /f /t", 0); //Process[] MyProcess1 = Process.GetProcessesByName(ProcessName); //Process MyProcess = new Process(); ////设定程序名 //MyProcess.StartInfo.FileName = "cmd.exe"; ////关闭Shell的使用 //MyProcess.StartInfo.UseShellExecute = false; ////重定向标准输入 //MyProcess.StartInfo.RedirectStandardInput = true; ////重定向标准输出 //MyProcess.StartInfo.RedirectStandardOutput = true; ////重定向错误输出 //MyProcess.StartInfo.RedirectStandardError = true; ////设置不显示窗口 //MyProcess.StartInfo.CreateNoWindow = true; ////执行强制结束命令 //MyProcess.Start(); //MyProcess.StandardInput.WriteLine("ntsd -c q -p " + (MyProcess1[0].Id).ToString());//直接结束进程ID //MyProcess.StandardInput.WriteLine("Exit"); Close(); } catch { } } private void timer2_Tick(object sender, EventArgs e) { if (Handle1 != GetForegroundWindow()) //持续使该窗体置为最前,屏蔽该行则单次置顶 { SetForegroundWindow(Handle1); //timer2.Stop();//此处可以关掉定时器,则实现单次置顶 } } } }