views:

141

answers:

4

Imagine we have a program trying to write to a particular file, but failing.

On the Windows platform, what are the possible things which might be causing the file to be un-writable, and what steps could be suggested to an end user/administrator to fix it.


Please include steps which might require administrator permissions (obviously users may not be administrators, but for this question, let's assume they are (or can become) administrators.

Also, I'm not real familiar with how permissions are calculated in windows - Does the user need write access to each directory up the tree, or anything like that?

+3  A: 

Some suggestions:

  • No write permission (get permission through Security tab on file Properties window; you must be the file owner or an Administrator)
  • File is locked (close any program that may have the file open, then reboot if that doesn't help)
  • File has the read-only DOS attribute set (unset it from file Properties window, or with attrib -r; you must be the file owner or an Administrator)

Edit 1: Only the second item (file is locked) has a possible solution that all users are likely to be able to do without help. For the first and third, you'll probably want to provide guidance (and hope the file wasn't made read-only intentionally!).

Edit 2: Technically, the user does need write and execute (chdir) permissions on all directories up to the root. Windows may skip some of the recursive checks up the tree as a performance optimization, but you should not rely on this because admins can force on these so-called "traverse checks" for certain users.

Edit 3: @RobM: Yes, you should check that there is no obvious reason that the user should not have the permissions she needs but does not have. I alluded to this in a less direct way in my first edit. However, in some cases users should have write permission to a file but do not because of filesystem corruption, a misbehaving program, or a mistake on their own part.

crosstalk
+1  A: 

If you are having trouble working out if the file is locked, try using Unlocker - it's a really useful free utility that shows you the process that has locked the file and lets you force an unlock if you need to.

Sean Kearon
A: 

On Vista could it also be that it's "marked" as unsafe because it's been downloaded from the internet and you have to click the unblock button on it's explorer properties dialog?

Sam Hasler
A: 

Lets change this around a bit. If your program is trying to write to a file and failing you either need to change the location of the file to one where the user can write to, or check the correct rights when the program starts and refuse to run if the user doesn't have them. Trampling over the system permissions is not the answer.