zoukankan      html  css  js  c++  java
  • 利用批处理文件实现 C#中程序自己删除自己



    using System.Runtime.InteropServices; 

    //****************************************添加引用

     [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";
                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);
     
               //************ 结束退出

                Close();
            }

  • 相关阅读:
    Codeforces D
    Codeforces 899E
    Codeforces 898F
    算法笔记--字符串hash
    算法笔记--归并排序
    Codeforces D
    Codeforces 101628A
    牛客练习赛7 E 珂朵莉的数列
    算法笔记--树的直径 && 树形dp && 虚树 && 树分治 && 树上差分 && 树链剖分
    Codeforces 895C
  • 原文地址:https://www.cnblogs.com/Fooo/p/1228252.html
Copyright © 2011-2022 走看看