The key method of suicide program c #

public static void TestForKillMyself()  
        {  
            string bat = @"@echo off  
:tryagain  
del %1  
if exist %1 goto tryagain  
del %0";  
            File.WriteAllText("killme.bat", bat);//写bat文件  
            ProcessStartInfo psi = new ProcessStartInfo();  
            psi.FileName = "killme.bat";  
            psi.Arguments = "/"" + Environment.GetCommandLineArgs()[0] + "/"";  
            psi.WindowStyle = ProcessWindowStyle.Hidden;  
            Process.Start(psi);  
        }

The above code has been tested effective, this method is called to create a project, at the end of the program, the program will automatically be deleted.

Reproduced in: https: //www.cnblogs.com/kevinGao/archive/2012/01/29/2336480.html

Guess you like

Origin blog.csdn.net/weixin_33795806/article/details/93286424