删除程序自身

 /// <summary>
        /// 删除程序自身
        /// </summary>
        private static void DeleteItself()
        {
            string vBatFile = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + "\DeleteItself.bat";
            using (StreamWriter vStreamWriter = new StreamWriter(vBatFile, false, Encoding.Default))
            {
                vStreamWriter.Write(string.Format(
                    ":del
" +
                    " del "{0}"
" +
                    "if exist "{0}" goto del
" +
                    "del %0
", System.Windows.Forms.Application.ExecutablePath));
            }

            //************ 执行批处理
            WinExec(vBatFile, 0);
            
            //************ 结束退出
           // System.Windows.Forms.Application.Exit();

            System.Environment.Exit(0);
        }

[System.Runtime.InteropServices.DllImport("kernel32.dll")]
public static extern uint WinExec(string lpCmdLine, uint uCmdShow);

 
原文地址:https://www.cnblogs.com/wdd812674802/p/10947683.html