你的位置:首页 > 软件开发 > ASP.net > C#删除程序自身【总结】

C#删除程序自身【总结】

发布时间:2016-03-10 09:00:08
出处:http://www.cnblogs.com/Interkey/  偶然看到一个可以自删除的程序,于是了解下如何实现。然后整理如下:  思路:  在.NET程序中,因为运行中的程序是受系统保护的,不能自己删除自身的,所以自删除的思路:  在关闭本程序之前启动新的进 ...

出处:http://www.cnblogs.com/Interkey/ 

 偶然看到一个可以自删除的程序,于是了解下如何实现。然后整理如下:

  思路:

  /// <summary>  /// 删除程序自身(本文地址:http://www.cnblogs.com/Interkey/p/DeleteItself.html)【推荐】  /// </summary>  private static void DeleteItself()  {    get='_blank'>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")]

  /// <summary>  /// 删除程序自身(本文地址:http://www.cnblogs.com/Interkey/p/DeleteItself.html)  /// </summary>  private static void DeleteItselfByCMD()  {    ProcessStartInfo psi = new ProcessStartInfo("cmd.exe", "/C ping 1.1.1.1 -n 1 -w 1000 > Nul & Del " + Application.ExecutablePath);    psi.WindowStyle = ProcessWindowStyle.Hidden;    psi.CreateNoWindow = true;    Process.Start(psi);    Application.Exit();  }
C#删除程序自身【总结】

 下面解释命令的意思:

  cmd /c 调用命令窗口执行dos指令

原标题:C#删除程序自身【总结】

关键词:C#

C#
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

可能感兴趣文章

我的浏览记录