7

I have the below script, it works fine, but how do I set it to keep security settings and add additional 'person' to the security group...

...and can cacls change the 'owner' of the folder?

I tired /e to edit instead of replace but it doesn't like it for some reason ?

Set WshShell = CreateObject("WScript.Shell")
strFolder    = "D:\test"

setPerms     = "%COMSPEC% /c echo Y| C:\windows\system32\cacls.exe """ & _
                strFolder & """ /G mydomain\myusername:F & pause" 'added pause to see what the outcome is

WshShell.run setPerms
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
Pavle Stojanovic
  • 525
  • 2
  • 8
  • 30

1 Answers1

16

CACLS is deprecated, you can achieve what you want with the recommended ICACLS. You want something like:

icacls.exe d:\test /grant domain\username:F

To make an addition to permissions and:

icacls.exe d:\test /setowner domain\username

To set ownership. Other options of interest from icacls /?:

/T indicates that this operation is performed on all matching
    files/directories below the directories specified in the name.

/C indicates that this operation will continue on all file errors.
    Error messages will still be displayed.
Jobbo
  • 1,358
  • 1
  • 8
  • 21