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);  
        }

以上代码经过测试有效,创建个项目调用此方法,在程序结束时,程序会自动被删除。