[Solved] VC++ fatal error LNK1168: cannot open filename.exe for writing

Suddenly, my Visual Studio Express 2010 C++ stopped rebuilding my project.
When I first hit F7 the project builds and runs fine (heck, it’s a hello world example).

Then I make some changes and hit F7 again, then I get:

1>LINK : fatal error LNK1168: cannot open C:UsersusernameDocumentsVisual Studio 2010ProjectsconsoleDebugconsole.exe for writing**<br><br>

Now the funny thing comes:

  1. The app is not running and it’s not shown in task manager.
  2. Going into the project directory and trying to remove it with hands comes with success but the file APPEARS AGAIN FROM NOWHERE.
  3. The system restore is disabled.
  4. I also tried to take the ownership of the whole damn drive.
  5. Every time I delete the file it recreates itself again but sometimes it stops doing that.
  6. If I delete the file (and it recreates after that), and then I start sysinternals procmon then the file dissapears.
  7. If I start procmon before – then the file keeps appearing after delete like always.

OS: W7 SP1 64-bit, with latest updates

Any ideas, please?

Enquirer: gogiii


Solution #1:

Enable “Application Experience” service. Launch a console window and type net start AeLookupSvc

Respondent: Software_Designer

Solution #2:

The problem is probably that you forgot to close the program and that you instead have the program running in the background.

Find the console window where the exe file program is running, and close it by clicking the X in the upper right corner. Then try to recompile the program. In my case this solved the problem.

I know this posting is old, but I am answering for the other people like me who find this through the search engines.

Respondent: CodeMed

Solution #3:

Restarting Visual Studio solved the problem for me.

Respondent: Aleksei Mialkin

Solution #4:

I’ve encountered this problem when the build is abruptly closed before it is loaded. No process would show up in the Task Manager, but if you navigate to the executable generated in the project folder and try to delete it, Windows claims that the application is in use. (If not, just delete the file and rebuild, which generates a new executable)
In Windows(Visual Studio 2019), the file is located in this directory by default:


To end the allegedly running process, open the command prompt and type in the following command:

taskkill /F /IM ApplicationName.exe

This forces any running instance to be terminated.
Rebuild and execute!

Respondent: Amal K

Solution #5:

In my case, cleaning and rebuilding the project resolved the problem.

Respondent: Hau Le

Solution #6:

well, I actually just saved and closed the project and restarted VS Express 2013 in windows 8 and that sorted my problem.

Respondent: Sparsh Jain

Solution #7:

The Reason is that your previous build is still running in the background.
I solve this problem by following these steps:

  • Open Task Manager
  • Goto Details Tab
  • Find Your Application
  • End Task it by right clicking on it
  • Done!
Respondent: back2Lobby

Solution #8:

This can also be a problem from the improper use of functions like FindNextFile when a FindClose is never executed. The process of the built file is terminated, and the build itself can be deleted, but LNK1168 will prevent a rebuild because of the open handle. This can create a handle leak in Explorer which can be addressed by terminating and restarting Explorer, but in many cases an immediate reboot is necessary.

Respondent: Laurie Stearn

Solution #9:

I know this is an old question but thought I’d share how I resolved the issue.

If you’re using Visual Studio and this error occurs, you can try to attach to process (CTRL+ALT+P) and find the “(program).exe” process. When you try to attach to it, an error will display stating that it failed to attach which removes the process from “running” (even though it’s not…) You’ll also be able to delete the (program).exe from your Debug folder.

Hope this helps someone! 🙂

Respondent: tw1tch01

Solution #10:


None of the solutions in this page worked for me EXCEPT THE FOLLOWING

Below the comment sections of the second answer, try the following :

Adding to my above comment, Task Manager does not display the
filename.exe process but Resource Monitor does, so I’m able to
kill it from there which solves the issue without having to reboot.
A__ Jun 19 ’19 at 21:23

Solution #11:

I also had this same issue. My console window was no longer open, but I was able to see my application running by going to processes within task manager. The process name was the name of my application. Once I ended the process I was able to build and compile my code with no issues.

Respondent: Jason

Solution #12:

Start your program as an administrator. The program can’t rewrite your files cause your files are in a protected location on your hard drive.

Respondent: chosen

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy