【发布时间】:2020-10-27 02:18:19
【问题描述】:
我想打开(或创建进程)目录特定位置并关闭(或杀死进程)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Process ps;
private void button1_Click(object sender, EventArgs e)
{
ps = Process.Start("explorer.exe", @"C:\test");
MessageBox.Show(ps.Id.ToString());
}
private void button2_Click(object sender, EventArgs e)
{
ps.Kill();
}
}
}
但是发生了错误 “无法处理请求,因为进程已退出。”
编辑
我想创建进程(“explorer.exe C:\test”)(单击按钮 1)并杀死前面的进程(单击按钮 2)。 “单击按钮 1”,然后“单击按钮 2”。
我预测 "进程 ps = Process.Start("explorer.exe C:\test");" 可以杀人 “ps.Kill()”。
但是 ps(进程变量)已经消失(被杀死?)并且无法杀死创建的目录进程(“explorer.exe”,@“C:\test”)。
如何杀死我创建(或启动)的 explorer.exe 进程
如何杀死由 Process.Start("explorer.exe") 创建的进程?
【问题讨论】:
-
@Martheen 不是我想要的并编辑问题,谢谢
标签: c#