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.