I am not really sure what happened (although I am willing to place some blame on Git file attribute handling) but suddenly some of my batch files started reporting “Windows cannot access the specified device, path, or file. You may not have the appropriate permissions to access the item.” when I try to start them from Windows Explorer. Annoyingly I could still start that same batch from Windows command line. Only double-click wouldn’t work.
After short investigation culprit was found in the permissions. Some application (Git) changed permissions for the file to include only read permissions. As soon as I changed permissions to include executable, I could start script again. Heck there is even a way to get executable attribute into Git repository so this can be avoided in the future. However, I took this as an opportunity to update permissions for my drive.
Drive in question is NTFS but not because I need any permission handling capabilities. Mostly it is because way NTFS handles small files is superior to any other Windows-supported file system. So my permissions on given drive are literally just allowing all users access. With time and different computers this changed a bit so reset was in order. I wanted to allow all users full drive access.
After starting Command Prompt as an administrator first mandatory task was to switch to that drive. Not only that this allows me to use relative paths further down the road but it also makes it less likely that any errors (e.g. due to accidentally forgotten parameter) would impact my system drive.
A:
Next step was to take ownership of my whole drive, forcing change when necessary:
TAKEOWN /F * /R /D Y
SUCCESS: The file (or folder): "A:\Test\Test1.txt" now owned by user "TEST\Josip".
SUCCESS: The file (or folder): "A:\Test\Test2.txt" now owned by user "TEST\Josip".
SUCCESS: The file (or folder): "A:\Test\Test3.txt" now owned by user "TEST\Josip".
...
Since previous command left a lot of output, I also used /setowner
option of ICACLS
. There is no benefit to this one other than showing me stats and ensuring a file hasn’t been missed. Yes, you can even use this command instead of TAKEOWN
but it has no option of forcing ownership change so you might need TAKEOWN
regardless.
ICACLS .\ /setowner Josip /T /C /Q
Successfully processed 119121 files; Failed processing 0 files
Next I set my root directory to allow all Users, Administrators, and SYSTEM groups in. From previous run I had Everyone and BUILTIN set so I decided to remove them while I am at it.
ICACLS .\ /grant:r Users:F Administrators:F SYSTEM:F /inheritance:e /remove Everyone /remove BUILTIN
processed file: .\
Successfully processed 1 files; Failed processing 0 files
And last step was what I really wanted. Just reset all permissions.
ICACLS * /reset /T /C /Q
Successfully processed 119120 files; Failed processing 0 files
And now I have my drive just as I wanted it.
PS: If you just wanna sort out Git, you can also update executable bit and avoid whole issue.