how to (using command-line/batch file only) make some file impossible to delete/rename for all users. I tried attrib +R on file itself and on directory where it exist but it doesn't help
Asked
Active
Viewed 128 times
1
-
You can't deny users with administrative rights from taking back access to the file. There are limitations to what you are trying to do. Also, without knowing exactly which user accounts have what permissions, it will be difficult to make this batch file. – CoveGeek Feb 19 '16 at 15:12
2 Answers
1
CACLS will do the trick. When you say all users however, the system user will still have privileges in most cases.
https://superuser.com/questions/222256/change-windows-7-file-permissions-from-command-prompt

Jonathan Piccirilli
- 157
- 5
-
Not exactly. Calc is depreciated so Im using icalc. It's doing its job but it doesnt matter since user can add permissions to him again – szemi Feb 19 '16 at 09:45
-
Once the user has no view rights, they will not be able to see the file. That should make it difficult to change permissions. :) – Jonathan Piccirilli Feb 19 '16 at 15:15
1
Here is a solution you can try.
You pass the full path and file to the batch file within quotes for security.
TAKEOWN /A "%~1"
ICACLS "%~1" /grant:r SYSTEM:(F) Administrators:(F) users:(R)
The /grant:r
will reset the permissions of the file to what is specified.
Again, if any user is a member of the administrator group then can reset the permissions to any file or folder.

CoveGeek
- 186
- 1
- 7