Today I tried to copy files and folders off a USB hard disk (NTFS formatted) on my Windows 7 desktop. I encountered multiple files with permission problems. The manual method to change permissions is very tedious, so I created a script (DOS batch file) to do the same.

Manually

During the copy operation. I got this error to "provide administrator permission to copy this file." Not very helpful and initially very worrying!

File Access Denied during Copy

First, find the offending file - you'll notice the path is not given so even finding the right culprit is a nightmare in itself.

Then, right click > Properties > Security. You'll see this message instead of the usual security info. Hit Continue. And select a user to assign ownership to - I chose Administrators.

Advanced Security Settings to assign ownership

A dialog box will confirm the ownership change but mention something to the effect that access rights are still not set. So hit Continue again, and this time you'll get this dialog:

Permissions granted to invalid users

You'll notice the access rights (full control, modify, read, etc.) are assigned to two unknown users that used to live on another computer. Anyway, hit Add:

Select Users of Groups to add access

I decided to add all Administrators - type in "Administrators" in the text box and hit ok. But you could add Everyone too I think.

And now if you look and the security properties, you'll get something like this. Make sure you allow "Full control".

Permissions to Allow Administrators Full Control

Hit OK in all dialogs. And if your error message in the first screen shot above is still on-screen, just click Continue and if all's well, the file copy operation will resume where it got stuck.

That was a lot of clicks!

Scripting

As always, be careful and validate. Run takeown/? and icacls to check what I'm doing here for yourself!

Here's the alternative. Create a batch file, e.g. fixaccess.cmd:

if /i %1 equ "" goto :eof
pushd
cd "%1"
takeown /R /F .
icacls . /grant Administrators:(OI)(CI)F /T
popd

Open cmd using Run as Administrator. Then run fixaccess "X:\bad\folder" replacing the path as appropriate.

That should do it. And if your error message in the first screen shot above is still on-screen, just click Continue.