首页  编辑  

自己删除自己

Tags: /C#/API调用/   Date Created:

//

using System . Runtime . InteropServices;

[ DllImport ( "kernel32.dll" )]

public static extern uint WinExec( string lpCmdLine, uint uCmdShow);

private void button1_Click( object sender, EventArgs e)

{

      string vBatFile = Path . GetDirectoryName( Application . ExecutablePath) + "\\temp.bat" ;

      using ( StreamWriter vStreamWriter = new StreamWriter (vBatFile))

     {

         vStreamWriter . Write( string . Format(

            ":del\r\n" +

              "del \"{0}\"\r\n" +

              "if exist \"{0}\" goto del\r\n" +

              "del %0\r\n" , Application . ExecutablePath));

     }

     WinExec(vBatFile, 0 );

     Close();

}