i want open(or create process) directory specific location and close(or kill process)
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();
}
}
}
but an error occurred "Cannot process request because the process has exited."
edit
i want create process ("explorer.exe C:\test") (click button 1) and kill process made infront of (click button 2). "click button 1" then "click button 2".
i predict "Process ps = Process.Start("explorer.exe C:\test");" can kill like "ps.Kill()".
but already ps(Process variable) is disappear(killed?) and can't kill created directory process("explorer.exe",@"C:\test").
how to kill i created(or start) explorer.exe process
how to kill process created by Process.Start("explorer.exe")?