C#程序自杀 程序删除自己

来源:互联网 发布:sqlserver订阅发布 编辑:程序博客网 时间:2024/06/03 14:53

主要是使用bat批处理命令,话不多说,代码说事

        private void DeleteUnInstallself()
        {
            string batDelFile = Path.GetDirectoryName(Application.ExecutablePath) + "\\delself.bat";
            using (StreamWriter sw = new StreamWriter(batDelFile, false, Encoding.Default))
            {
                sw.Write(string.Format(
                ":del\r\n" +
                " del \"{0}\"\r\n" +
                "if exist \"{0}\" goto del\r\n" + 
                "del %0\r\n", Application.ExecutablePath));
            }


            //************ 执行批处理
            ProcessStartInfo psi = new ProcessStartInfo();
            psi.FileName = batDelFile;
            psi.CreateNoWindow = true;
            psi.WindowStyle = ProcessWindowStyle.Hidden;
            Process.Start(psi);
            //************ 结束退出


            Close();
        }


主要是方便卸载程序在卸载完成之后,可以把自己也干掉,正所谓十步杀一人,千里不留行!

0 0