C#程序自殺 程序刪除自己

主要是使用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();
        }


主要是方便卸載程序在卸載完成之後,可以把自己也幹掉,正所謂十步殺一人,千里不留行!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章