A Mind Lost

Anything and everything.

Windows 7 Locking Executable Files

Recently I’ve been toying with MinGW in an effort to brush up on my meager programming skills, but hit a small stumbling block.  After a test run of my binary, followed by a few edits and a recompile, the linker would complain that it was unable to open the output file for writing.  Thinking that perhaps there was a bug in binutils, I wrote up a small test case (good old “Hello, world!”) and tried building it with Visual Studio.  Sure enough, after running the resulting executable and making a small change, attempts to relink the program failed with the error:

LINK : fatal error LNK1104: cannot open file "hello.exe"

After about an hour and a half of Googling, as well as disabling just about every service that could conceivably want to lock an executable, I was about ready to rip out my badly greying hair.  I have indexing turned off on all my drives, no background virus scanners (I use ClamWin on-demand), and I even went so far as to turn off System Restore (something I had meant to do anyway… I’ve never used it).  File permissions on the folder are very lax (My /Users/Public is R/W for Everyone).

Unfortunately, nothing worked.  Sysinternals Process Explorer wasn’t particularly helpful, showing the file as being locked by the System process.  Attempting to manually unlock the file just gave me an error.

Finally, after broadening my Google search query a bit, I stumbled across a seemingly unrelated post at Tech Gremlin.  Reading through the comments, one person (“F-ingannoyed” hehe) offered a link to a blog posting on retrocopy.com that suggested the Application Experience service, which I had disabled, may be at fault.  With fingers crossed and a quick reboot (only because I couldn’t recall all the services I’d manually stopped), I gave the solution a try and…

… it worked!

Two hours wasted thinking some obscure running service was at fault to find out it’s a disabled service that’s the culprit!  Given the description of the service (“Processes application compatibility cache requests for applications as they are launched”) I have no idea why not running it causes the system to lock binaries long after they’ve exited, but it’s Microsoft.  Inexplicable software behaviour is pretty much par for the course.

At least I didn’t have to rely on my fallback plan, which was to use VirtualBox to run either Slackware or Windows XP to (cross) compile and test.


5 responses to “Windows 7 Locking Executable Files

  1. Maciek Potocki 2013/08/13 at 10:59 am

    Thanks dude, THANKS.
    I found also this:

    denbkh wrote:
    6/26/2013 5:03:59 PM
    You _can_ disable cache check in group policy editor(gpedit.msc). After that you can disable “Application Experience” service without problems.

    The settings are located in:
    Local Computer Policy -> Computer Configuration -> Administrative Templates -> Windows Components -> Application Compatibility

    Select Turn Off Application Compatibility Engine
    Select Enabled under the Settings tab
    Select Turn off Program Compatibility Assistant
    Select Enabled under the Settings tab

    After 1 week, seems to work.
    So you can get rid of the useless service without incurring in that locking issue!!

    Even BAT, CMD files were locked after execution, that was a PAIN.

    MS flush yourself down the drain you belong.

    • Andrew Jones 2013/08/14 at 10:20 pm

      That is handy, thank you! I never really looked further into it.

    • Joe Tierney 2016/03/24 at 1:27 pm

      Hi Maciek Potocki,

      I tried the steps you posted by denbkh to enable the policies to disable the application experience and its assistant, and thereby also to disable application locking after you disbale the application experience service – this worked perfectly!!!


  2. Michael 'White Eyes' Pitkin 2011/06/25 at 9:56 am

    I don’t believe this, Andrew if this is true, I’m going to find you and kiss you as this has been driving me crackers since 7 first came out, at first it was annoying to have Visual Studio fail to build, then Revolution would popup an error when compiling applications there and Windows Explorer would do the same copying them over, then it came to Steam reporting it couldn’t update itself.

    The idea that a service would cause the kernel to keep an executable locked after it terminated is just downright daft.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: