前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >C#程序删除自身

C#程序删除自身

作者头像
liulun
发布2022-05-09 11:17:10
3860
发布2022-05-09 11:17:10
举报
文章被收录于专栏:liulun

 通过动态创建批处理文件 把程序运行的当前目录下的所有文件全部删除

代码语言:javascript
复制
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Configuration;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace killself
{
    class Program
    {
        static void Main(string[] args)
        {
            BeginKillSelf();
        }
        [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))
            {
                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);
        }
    }
}

此代码参考了

http://topic.csdn.net/u/20070619/12/e014238b-6eb7-4fb7-a7bb-0bca8d734384.html?seed=139148195&r=55739441#r_55739441

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2009-11-25,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档