您的位置:首页 > 编程语言 > C#

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

2016-04-29 17:03 423 查看
主要是使用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();

        }

主要是方便卸载程序在卸载完成之后,可以把自己也干掉,正所谓十步杀一人,千里不留行!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息