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

205,416

Solution 1

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

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.

Solution 3

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:

%USERPROFILE%\source\repos\ProjectFolderName\Debug

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!

Solution 4

Restarting Visual Studio solved the problem for me.

Solution 5

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

Share:
205,416
gogiii
Author by

gogiii

Updated on July 09, 2022

Comments

  • gogiii
    gogiii almost 2 years

    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:\Users\username\Documents\Visual Studio 2010\Projects\console\Debug\console.exe for writing**<br><br>
    

    Now the funny thing comes:

    1. The app is not running and it's not shown in the 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 disappears.
    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?

    • User
      User over 9 years
      For me a simple reboot fixed this error (similar to CodeMed's answer below).
  • DJMcMayhem
    DJMcMayhem about 9 years
    This fixed it for me. I will say though, I had to look under processes in windows task manager, because the console window disappeared.
  • Wai Ha Lee
    Wai Ha Lee about 9 years
    Hi Sparsh Jain, the question mentioned that "visual studio express 2010" on "W7 SP1" was being used. Moreover I don't think that your answer doesn't add anything that existing answers haven't covered.
  • Ahx
    Ahx over 8 years
    Windows 10 gives me the error : "The service name is invalid"
  • David G
    David G over 7 years
    How do I enable application experience?
  • Florin
    Florin over 7 years
    It worked for me. Another ridiculous Windows hack. Microsoft should pay Google a hefty sum for supporting its OS, otherwise no one would be able to use the thing.
  • STF
    STF almost 7 years
    Thanks! I did that with VS 2015 on windows 10 and it helped me :) I think that's the easiest way to solve this problem.
  • sitaram chhimpa
    sitaram chhimpa over 6 years
    I am not able to close by X button is there any other way...? One way i found is lose your IDE and then it will automatically close prompt window.
  • M.Mahdipour
    M.Mahdipour over 6 years
    Worked for me on windows 7 Visual Studio 2013 C++
  • Astinog
    Astinog about 5 years
    @AhmetTavli I have the same problem. The service seems to not be available in Win10. Have you found a solution to this?
  • Ahx
    Ahx about 5 years
    @Astinog I have been using Mac for more than 2 years, therefore I forgot the solution. I'm sorry
  • A__
    A__ almost 5 years
    Win10 VS 2017. Quitting everything until there was nothing of relevance in the task manager doesn't help, instead I have to reboot the machine. When shutting down an error dialog suddenly appears and is immediately closed out of, presumably this dialog needed to be closed before the debugger could access the app again but the dialog does not appear (until shutting down). Perhaps this process existed in the task manager but with a generic/unhelpful name.
  • A__
    A__ almost 5 years
    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.
  • Daneel Olivaw
    Daneel Olivaw about 4 years
    I actually had to restart the whole computer.
  • M.Ionut
    M.Ionut about 4 years
    @CodeMed oopsie..this is why I love StackOverflow
  • passionateProgrammer
    passionateProgrammer over 3 years
    Hey A__, you have saved my time a lot. I used to reboot my computer and it was so annoying and time-consuming. none of those above worked. but your solution was the only one works perfectly. Thank you so much.
  • Beko
    Beko over 3 years
    Thanks, this did it for me. Had the exact same problem (.exe wouldn't show up in Task Manager)
  • J-D3V
    J-D3V over 2 years
    Wow, I am a Kufing idiot. You know, you might think that MS would suggest that you check to make sure your command-line application is closed... FML...