Thursday, December 4, 2008

Can a Program commit suiside?

Yes. A proram can delete itself after running.
You can verify this by running the exe inside this zip file.

Thanks to Alex for the solution.Great thought.
Here is the C# code

Process.Start("cmd.exe", "/C choice /C Y /N /D Y /T .5 & Del " + Application.ExecutablePath);
Application.Exit();//This is needed in the case of Windows application.

Some technical things.
The choice is playing major role here.It delays the deletion by .5 secs .The delay gives enouhg time for the program to get removed from the memory. Else it won't get deleted.
If you need more details about choice open a command prompt then type 'choice /?'

No comments: