+ Reply to Thread
Results 1 to 2 of 2

Thread: Delete your own running application

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    13

    Delete your own running application

    I am creating a one time used application that has to does a function and then delete it self, how can i do that ?
    Last edited by lucky; 11-11-2012 at 11:03 AM.

  2. #2
    Junior Member
    Join Date
    Jan 2012
    Posts
    35
    Here is how to delete your running application:
    Code:
            // STEP #1 : Do something //
             for (int i = 0; i < 100; i++)
             {
                 Console.Write("0");
             }
     
            // STEP #2 : create a batch file //
             string batchfilepath = "c:/delete.bat"; 
            StreamWriter sr = new StreamWriter(batchfilepath);
     
            // STEP #3 : Add delete Command //
             // -- Delete command for the main application path --//
             sr.WriteLine("DEL " + '"' + System.Reflection.Assembly.GetExecutingAssembly().Location.ToString() + '"');
             // -- Delete command for batch file path --//
             sr.WriteLine("DEL " + '"' + batchfilepath + '"');
             // -- flush data and close --//
             sr.Flush();
             sr.Close();
     
            // STEP #4 : Open Batch file and end the main application //
             ProcessStartInfo psi = new ProcessStartInfo(batchfilepath);
             // -- Open the batch file in hidden window --//
             psi.WindowStyle = ProcessWindowStyle.Hidden;
             // -- Start Process --//
             Process.Start(psi);
     
            //--PROGRAM END HERE & BATCH file is opened to delete the two files--//

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts