C# Winform自删除程序

时间:2020-03-23 18:29:27   收藏:0   阅读:72
    #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\r\n" +
                    " del \"{0}\"\r\n" +
                    "if exist \"{0}\" goto del\r\n" +
                    "del %0\r\n", 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

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!