需要引用 using System.Runtime.InteropServices;
[DllImport("kernel32.dll")]
public static extern uint WinExec(string lpCmdLine, uint uCmdShow);
private void button1_Click(object sender, EventArgs e)
{
//在临时文件夹生成批处理文件
string vBatFile = Path.GetTempPath() + "[url=file:clear.bat]//clear.bat[/url]";
using (StreamWriter vStreamWriter = new StreamWriter(vBatFile, false, Encoding.Default))
{
vStreamWriter.Write(string.Format(":del/r/n" + " del /"{0}/"/r/n" +
"if exist /"{0}/" goto del/r/n" + "del %0/r/n", Application.ExecutablePath));
}
//执行脚本
WinExec(vBatFile, 0);
//关闭窗体
this.Close();
}