I need to shut down my application and then delete the executable. I am doing it by kicking off a low priority batch job and then immediately shutting down the exe. Is there a better way?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As long as any code from an executable is in memory, it cannot be deleted, but there are some other things you can try:
MoveFileExto defer the delete until next reboot is one approach typically used by install/uninstall code.cmd.exe /c del c:\path\myprog.exeto run 60 seconds from now, then quit promptly so it has a chance of succeeding.If you’re using the batch file method, consider something like the following:
The
pingcommand here is being abused to insert a delay, sincesleepis not a standard command on Windows. The loop enables the batch process to bide its time until it can actually remove the executable.