none
fatal error LNK1168: cannot open 'filename.exe' for writing

    Question

  • When I first compile and link a solution, everything works fine. However, often (about 60 - 70% of the time), subsequent link operations fail unable to open the .exe file for writing. I've checked the obvious things such as the application still running and even trying to delete the existing file via explorer fails saying the file is in use.

     

    If I wait long enough - sometimes up to 5 minutes - then all works well again. I haven't worked out when this happens. It usually happens if I encounter an unhandled exception during a test run, but sometimes I get this even when the test run was clean.

     

    Any ideas?

    Sunday, August 12, 2007 3:33 PM

Answers

All replies

  • How have you the checked that the application is still running? Have you used the Tak Manager?

    Monday, August 13, 2007 3:24 AM
  • If you've got an aggressive anti virus application installed, that may also hog the file. To find out quickly, download the "Handle" tool from Sysinternals (http://www.microsoft.com/technet/sysinternals/utilities/handle.mspx), and start it with "handle filename.exe". That should show all applications currently using / holding it.
    Monday, August 13, 2007 11:20 AM
    Moderator
  • Thanks to both Simple Samples and einaros.

     

    Yes - I checked task manager but the app wasn't running.

     

    I suspect that my AV (Norton) might be involved so I'll download the utility you mention and give it a go. I'll keep you posted.

    Saturday, August 18, 2007 6:34 PM
  • look for filename.exe in process.

    and finish the filename.exe.
    Tuesday, January 06, 2009 8:02 AM
  • Sorry to ressurect an old thread, but I have this exact same problem on Windows 7 64-bit with Visual Studio 2010.  The linker fails with the error:

    1>LINK : fatal error LNK1168: cannot open C:\yadada\myapp.exe for writing

    Typically happens after I run the program from Visual Studio, then close the program.  The process shuts down and does not show up in either the process manager, or from the commmand line using the 'handle application.  I get this error around 75% of the time.

    Here is what I have tried:

    • The application 'myapp.exe' has closed down cleanly I think.  It is not on the process list in the Windows Task Manager
    • Sysinternal's program 'Handle' doesn't find any matching handles for 'myapp.exe'
    • The freeware program 'Unlocker 1.9.0' doesn't think the file is locked
    • I can manually delete the file
    To get around this error, I have to:
    1. Manually delete the file through Windows Explorer, or
    2. Wait a few minutes, then try building again.
    Any solution?

     

     

     

     

     

     

     

     

    Tuesday, July 20, 2010 1:26 AM
  • On Tue, 20 Jul 2010 02:26:34 +0100, <Kato2> wrote:

    >
    > Stars: 1; Post: 13;
    >
    >
    > Sorry to ressurect an old thread, but I have this exact same problem on
    > Windows 7 64-bit with Visual Studio 2010. The linker fails with the
    > error: 1>LINK : fatal error LNK1168: cannot open C:\yadada\myapp.exe for
    > writing Typically happens after I run the program from Visual Studio,
    > then close the program. The process shuts down and does not show up in
    > either the process manager, or from the commmand line using the 'handle
    > application. I get this error around 75% of the time. Here is what I
    > have tried: The application 'myapp.exe' has closed down cleanly I think.
    > It is not on the process list in the Windows Task Manager Sysinternal's
    > program 'Handle' doesn't find any matching handles for 'myapp.exe' The
    > freeware program 'Unlocker 1.9.0' doesn't think the file is locked I can
    > manually delete the file To get around this error, I have to: Manually
    > delete the file through Windows Explorer, or Wait a few minutes, then
    > try building again. Any solution?

    Try adding an exception to your anti-virus software.

    --
    Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


    Tuesday, July 20, 2010 10:34 AM
  • I disabled the antivirus, I'm using Norton Security Suite.  The problem has not gone away.  I also have problems with the Windows 7 filesystem not always updating the explorer window after file operations.  I suspect this is related.

    Frustrating... i need to go back to Windows XP i think, this is my work machine.

    Anyone have similar problems?

    I am using TortoiseSVN and Elaborate Bytes Virtual CD-ROM Drive that might be causing the problem.

    • I changed the "DontRefresh" key from 1 to 0 in HKEY_CLASSES_ROOT\CLSID\{BDEADE7F-C265-11D0-BCED-00A0C90AB50F}\Instance\.
    • Uninstalled Virtual CD-ROM Drive
    Hopefully this will solve the problem, will post results.
    Thursday, July 22, 2010 1:12 AM
  • This didn't solve the problem.  I uninstalled Virtual CD-ROM, uninstalled Tortoise SVN, and completely uninstalled my Norton antivirus program (currently running without antivirus).

    I also tried the suggestions at http://social.technet.microsoft.com/Forums/en/w7itproui/thread/9f51f5ae-e3cb-4877-ab88-4e8d49f543c2, and changed the .reg file follows:

    Windows Registry Editor Version 5.00

    [HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{BDEADE7F-C265-11D0-BCED-00A0C90AB50F}]
    @="&Discuss"

    [HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{BDEADE7F-C265-11D0-BCED-00A0C90AB50F}\Implemented Categories]

    [HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{BDEADE7F-C265-11D0-BCED-00A0C90AB50F}\Implemented Categories\{00021494-0000-0000-C000-000000000046}]

    [HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{BDEADE7F-C265-11D0-BCED-00A0C90AB50F}\InprocServer32]
    "ThreadingModel"="Apartment"
    @="shdocvw.dll"

    [HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{BDEADE7F-C265-11D0-BCED-00A0C90AB50F}\Instance]
    "CLSID"="{4D5C8C2A-D075-11D0-B416-00C04FB90376}"
    "DontRefresh"=dword:00000000

    [HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{BDEADE7F-C265-11D0-BCED-00A0C90AB50F}\Instance\InitPropertyBag]
    "URL"="C:\\PROGRA~2\\MICROS~2\\Office12\\INTLBAND.HTM"

    This also did not work.

    Thursday, July 22, 2010 7:51 AM
  • I can confirm this behavior with Windows 7. Sadly, I don't have a fix. This seems to be relatively recent behavior. I suspect a Windows update is the cause as I can restore my system to a couple months ago and the problem goes away.

    I've noted several other aberrations with the file system and Explorer. Files with unknown content (such as files without an extent) can cause a debug exception and crash Explorer. This too seems to be a recent behavior change.

    Could it be related? Could it have something to do with the search indexing?

    Thursday, August 19, 2010 5:24 PM
  • I also have exact same problem.After installation of win7 i disabled a lot of things:Search indexing,aero etc.Now i also have the problem with the file system lagging behind-I make a file and have to wait 1 min before explorer shows the file(it rarely happens).

    I have quick fix for fatal error LNK1168:

    make the .exe file run on Compatibility mode,use Windows Xp SP3.Maybe other Comp. modes also work,that i dont know,for me it works with xp sp3.

    Tuesday, September 07, 2010 5:28 PM
  • Riiul, interesting...

    Saw this post:
    • https://connect.microsoft.com/VisualStudio/feedback/details/586436/system-locks-exe-on-build?wa=wsignin1.0

    Suggests that SYSTEM (pid 4) has a lock on the exe file for about 30-60 seconds after each compilation. "Obviously I cannot shut down that process as that would close smss.exe."   Then later he says he turned off Application Experience and this solved the problem.

    Here is a blurb about turning it off.

    • http://wiki.blackviper.com/wiki/Application_Experience

    I am going to try this and see if this solves the problem.

    BTW, can someone mark this thread a UNANSWERED?  This has nothing to do with antivirus.

    Thursday, September 16, 2010 11:49 PM
  • okay guys here is the solution.

    JUST TURN ON THE "APPLICATION EXPERIENCE SERVICE" IN YOUR SERVICES SETTING OF WINDOWS

    I solved by this way and it works like a charm :)

    http://gauravpandey.com/wordpress/?p=291

     

    • Proposed as answer by TollPhree Wednesday, September 14, 2011 5:29 AM
    Wednesday, September 22, 2010 6:40 PM
  • Kato2...

    This thread has already been marked as answered over 3 years ago. It was resurrected to ask a similar question, but...it would not be appropriate to unmark an answer to the original question. The solution is to start another thread, not remove an answer, regardless of whether you agree with it, or not. (Besides, Windows7 and VS2010 were not released in 2007, so the new question is off-topic, anyway.)

    Wednesday, September 22, 2010 7:06 PM
  • I appreciate your diligence! I was struggling with the same problem and I was going to give up! Thank you.
    Tuesday, April 12, 2011 8:28 AM
  • okay guys here is the solution.

    JUST TURN ON THE "APPLICATION EXPERIENCE SERVICE" IN YOUR SERVICES SETTING OF WINDOWS

    I solved by this way and it works like a charm :)

    http://gauravpandey.com/wordpress/?p=291

     

    Thanks a lot, works like a charm now.
    Friday, April 15, 2011 9:37 AM
  • Thank you so much for posting this fix!!  it worked like a charm. :)

    Wednesday, September 14, 2011 5:29 AM
  • okay guys here is the solution.

    JUST TURN ON THE "APPLICATION EXPERIENCE SERVICE" IN YOUR SERVICES SETTING OF WINDOWS

    I solved by this way and it works like a charm :)

    http://gauravpandey.com/wordpress/?p=291

     

    Thanks a lot, guy!
    Monday, March 18, 2013 5:06 PM
  • My teacher is just a geniuos.. he told me to close the .exe file, then just debug your VS proyect and, how my teacher say "be happy"
    • Proposed as answer by KarlaM8 Sunday, June 02, 2013 4:38 PM
    • Edited by KarlaM8 Sunday, June 02, 2013 4:39 PM
    Sunday, June 02, 2013 4:38 PM
  • Awesome.
    Monday, August 05, 2013 8:26 PM
  • I had that problem after making minor changes to my program.  I noticed that my debugging window was open from the previous build was still open, so i closed it and it worked.
    Thursday, September 25, 2014 8:26 PM