Have you ever had a program complain to you that a file was read only or “locked”? I’ve had this problem in the past several times and it can be extremely frustrating. Here’s some stuff to try.
Make sure the file is not read only
The obvious thing to check first is if the file actually is read only. If it is then it’s a pretty quick fix to change that through the file’s property panel. It’s also possible that your source control system may have reset the read only flag, if that’s the case you just need to check out the file again.
Make sure the file is unblocked
Sometimes when you download something from an insecure “zone” windows will mark it as a blocked file. I’ve found this can happen when you’re extracting a zip file from the internet. To change this go to the file’s property page and click the button to unlock the file.
Restart your computer
It’s possible that another program has this file open and refuses to close it.
Figure out what program is locking the file
It’s possible that a another program running on your system has opened the file and is preventing you from changing it. This can typically be fixed by restarting your computer but I’m usually a little more curious to find out what program actually has a grip on the file. It’s actually fairly easy to find this out.
This is just a zip file, just extract it and run procexp.exe. You will now see the main Process Explorer screen. This gives you lots of very detailed information about what is currently running on you computer.
Click the binoculars icon on the toolbar, or select “Find Handle or dll…” from the Find menu.
Type in the full path to the file you are having problems with and click search. If any currently running processes are using this file they will show up in this search. Clicking one of the results in this search will jump you to that process in the process list where you can then view more information about that program or potentially kill the program to free up the lock on the file.
Now you can solve the mystery of what program is locking my file!?!