怎样用C#写一个程序,专杀指定进程?
- 提问者网友:了了无期
- 2021-03-06 03:01
- 五星知识达人网友:低血压的长颈鹿
- 2021-03-06 03:45
编写过程:
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
{Memo1.Text+= "杀死" + processName + "失败!";
调用过程:
private void button1_Click(object sender, System.EventArgs e)
KillProcess("excel");}
- 1楼网友:不甚了了
- 2021-03-06 06:32
class screenprocess //进程管理相关 { public system.windows.forms.listbox processlistbox = new system.windows.forms.listbox();
public void getallprocess()//获取进程 { this.processlistbox.items.clear(); system.diagnostics.process[] myprocesses = system.diagnostics.process.getprocesses(); foreach (system.diagnostics.process myprocess in myprocesses) { this.processlistbox.items.add(myprocess.processname); } this.processlistbox.selectedindex = 0; }
public void killprocess(string name)//杀死进程 { system.diagnostics.process[] myprocesses = system.diagnostics.process.getprocesses(); foreach (system.diagnostics.process myprocess in myprocesses) { if (name == myprocess.processname) { myprocess.kill(); } } }
}
- 2楼网友:詩光轨車
- 2021-03-06 04:54