C# Winform自删除程序

    #region MyRegion

        /// <summary>
        ///
        /// </summary>
        private static void DeleteItself()
        {
            string vBatFile = Path.GetDirectoryName(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
", Application.ExecutablePath));
            }
            //************ 执行批处理
            WinExec(vBatFile, 0);
            //************ 结束退出
            Application.Exit();
        }
        [System.Runtime.InteropServices.DllImport("kernel32.dll")]
        public static extern uint WinExec(string lpCmdLine, uint uCmdShow);

        #endregion

  

原文地址:https://www.cnblogs.com/simadi/p/12553737.html