[DllImport("kernel32.dll")] public static extern uint WinExec(string lpCmdLine, uint uCmdShow); private void button1_Click(object sender, EventArgs e) { string vBatFile = Path.GetDirectoryName(Application.ExecutablePath) + "\\Zswang.bat";//这个是bat文件 不可更改成别的名称。 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); }
标签:StreamWriter,string,删除,winfrom,自己,Application,del,vBatFile,WinExec From: https://www.cnblogs.com/webenh/p/18216584