Changing Folder Permissions in vbscript

icaclsvbscript

I have a vbscript that will create a folder, but I need the User to have Full Permissions. I have put my code below. (Windows 8 system)

FSO.CreateFolder(lclFolder)
oWS.exec "icacls " & lclFolder & " /reset /inheritance:r /grant:r Users:(OI)(CI)F /T"

I have the script running as Administrator using:

If Not WScript.Arguments.Named.Exists("elevate") Then
  CreateObject("Shell.Application").ShellExecute WScript.FullName _
    , WScript.ScriptFullName & " /elevate", "", "runas", 1
  WScript.Quit
End If

The folder gets created, but the User permissions were: read & execute, List folders contents & Read. After the icacls line was inserted, this did not change. Can anyone advise where I went wrong?

Best Answer

As per Exec Method (Windows Script Host):

The command line should appear exactly as it would if you typed it at the command prompt.

Therefore, force embedding folder name in a pair of " double quotes as follows:

oWS.exec "icacls """ & lclFolder & """ /reset /inheritance:r /grant:r Users:(OI)(CI)F /T"

or as follows:

oWS.exec "icacls " & CHR(34) & lclFolder & CHR(34) & " /reset /inheritance:r /grant:r Users:(OI)(CI)F /T"
Related Question