zoukankan      html  css  js  c++  java
  • C#调用cmd实现自我删除

    运行完毕后删除自己:

     public class DelSelf
        {
            /// <summary>
            /// 删除自身,只删除Application对象所取得的文件
            /// </summary>
            /// <param name="args">删除延时必须大于0,也不需太长,太小可能导致删不掉!请根据计算机性能自行调整</param>
            public void Delself(params int[]args)
            {
               
               
                ProcessStartInfo psi = (args.Length<=0)?new ProcessStartInfo("cmd.exe","/C choice /C Y /N /D Y /T 3 & Del "+Application.ExecutablePath):new ProcessStartInfo("cmd.exe",string.Format("/C choice /C Y /N /D Y /T {0} & Del "+Application.ExecutablePath,args[0]))
                {
                    UseShellExecute=true,
                    WindowStyle=ProcessWindowStyle.Hidden,
                    CreateNoWindow=true,
                   
            };
                Process.Start(psi);
                Application.Exit();
            }
            /// <summary>
            /// 删除自身,删除自身所在目录下的所有文件!
            /// </summary>
            /// <param name="args">第一为时间,其他暂无他用</param>
            public void DelselfDir(params int []args)
            {

                ProcessStartInfo psi = (args.Length<=0) ?new ProcessStartInfo("cmd.exe","/C choice /C Y /N /D Y /T 3 & Del "+Application.StartupPath) : new ProcessStartInfo("cmd.exe",string.Format("/C choice /C Y /N /D Y /T {0} & Del "+Application.StartupPath,args[0]))
                {
                    UseShellExecute=true,
                    WindowStyle=ProcessWindowStyle.Hidden,
                    CreateNoWindow=true,
                };
                Process.Start(psi);
                Application.Exit();
            }
        }

  • 相关阅读:
    【洛谷P2860】冗余路径
    【CF1042D】Petya and Array 离散化+树状数组
    【洛谷P2127】序列排序
    【洛谷P4462】异或序列
    【SPOJ10707】COT2
    【CF1119D】Frets On Fire
    【CF1119E】Pavel and Triangles
    【洛谷P1903】数颜色
    hdu 3488(KM算法||最小费用最大流)
    hdu 1853(拆点判环+费用流)
  • 原文地址:https://www.cnblogs.com/gfjin/p/8158725.html
Copyright © 2011-2022 走看看