C#程序删除自身

    [DllImport("kernel32.dll")]
        public static extern uint WinExec(string lpCmdLine, uint uCmdShow);
        private static  void BeginKillSelf()
        {
            string vBatFile = Path.GetDirectoryName(Application.ExecutablePath) + "\\a.bat";
            using (StreamWriter vStreamWriter = new StreamWriter(vBatFile, false, Encoding.Default))
            {
          //删除自身bat vStreamWriter.Write(string.Format( ":del\r\n" + " del \"{0}\"\r\n" + "if exist \"{0}\" goto del\r\n" + "del %0\r\n", Application.ExecutablePath));

          //自动重启   

          //vStreamWriter.Write(string.Format(
          //"start {0}\r\n"+
          //"del %0\r\n", Application.ExecutablePath));

            }
            WinExec(vBatFile, 0);
            Process.GetCurrentProcess().Kill();
            Environment.Exit(0);
        }

  

posted @ 2024-02-23 10:35  Xingsoft  阅读(55)  评论(0编辑  收藏  举报