batch script to set user permissions

I've modified a batch script I found to set user permissions. The script creates a folder, then assigns permissions as full control to the "domain admins", "Administrators", and the "username", only it still assigns permissions to others also, for example "Everyone". Can someone please tell me why? I need to secure the folder for use only by the domain admins, administrators and "single" user.

Here's the code:

mkdir \\server\data\reports\username
echo y| calcs "\\server\data\reports\username /G" "Domain Admins":F "Administrators":F username:F

I've tried it several different ways but nothing works. It always creates a folder with full access for everybody in the company.

Who is Participating?
darkstar245Connect With a Mentor Commented:
Have you tried to remove everyone permissions by including it in the command?
Also, if I remember correctly, even with the calcs command it's going to inherit the permissions of the reports folder.  What is the access set to on that folder?
That's because the command never actually runs, because
1. the name of the command is cacls.exe, not calcs.exe
2. you don't have the quotes specified correctly
Then it's completely unnecessary to add Domain Admins, because Domain Admins are a member of the local Administrators group by default anyway; add local system instead.

mkdir \\server\data\reports\username
echo y| cacls.exe "\\server\data\reports\username" /G Administrators:F SYSTEM:F username:F

Open in new window

As an alternative I would consider using fileacl
which is an excellent and flexible tool for modifying user ACLs
if cacls is run without /e (*e*dit the ACL), it will *replace* the current ACL with the specified permissions; that's why the "echo y|" is necessary as well. The problem is the incorrect syntax.
fselliottAuthor Commented:
Yes, thank you, the problem is in the inherited permissions. But how do I remove them completely? I've re-written to this:

echo y|calcs.exe /e "\\server\data\reports\username" /R "CREATOR OWNER"

and it removes permissions, but it still allows it to inherit from parent the special permissions, which allow full access. So it defeats it's purpose.  Please provide guidance. Thanks, Lisa
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.