Search code examples
c++windowscrashdelete-filenmake

Unable to delete EXE after it crashes even though process not shown in Task Manager


I have a program that I have written that crashes and I'm in the process of debugging it.

However, the issue is that when I attempt to create a new build, very frequently (but not always!) I get the message:

Cannot open file 'TheExecutable.exe'

I am then unable to delete, rename, move, or in any way modify the executable until the system is rebooted. Attempting to do so in Windows explorer gives

The action can't be completed because the file is open in TheExecutable.exe Close the file and try again.

This behavior isn't unique to the particular crash I'm dealing with right now, nor the particular program. Development is becoming a headache as every attempt to debug will now take several minutes to reboot and bring all my tooling back up.

What, if anything, can I do to prevent Windows from "locking" the executable in such a fashion?

No running process for that executable is visible in Task Manager

Full details of build system:

  • Windows 10
  • Intel Compiler, 19.1.0.166 Build 20191121
  • nmake
  • C++14

Solution

  • Your process is not being terminated all the way. Since it is not list in the task manager, you can use PSKILL to end it manually.

    Open power shell or the console in administrator mode and run

    pskill name_of_executable
    

    and it should terminate it so you can re-run it.