editing advanced file security options with vbscript

  • Thread starter Thread starter pulathan
  • Start date Start date
P

pulathan

How can I edit advanced security options of a file or a
folder?
Here is the script that I use to read users.txt to get
related folder names and set these folders' security . I
also want the set advanced security options of the folders
for the users. I don't want the users can change their's
folder's security settings and take the ownership of the
folder. But all the others rights should be given to them.

Dim objWSH 'Windows Script Host Object
Dim objRTC 'Return
Dim arrFileLines()
i = 0
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\users.txt", 1)
'Adds the text file to array line by line
Do Until objFile.AtEndOfStream
Redim Preserve arrFileLines(i)
arrFileLines(i) = objFile.ReadLine
i = i + 1
Loop
objFile.Close
'Reads array and checks if the folder exist. If exist
gives the necessary rights.
For l = Lbound(arrFileLines) to UBound(arrFileLines)
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists("D:\" & arrFileLines(l) ) Then
Set objWSH = CreateObject("WScript.Shell")
'Set Change Permissions using CACLS.exe
strACLCommand = "cmd /c echo y| CACLS "
strACLCommand = strACLCommand & "d:\" & arrFileLines
(l)
strACLCommand = strACLCommand & " /g " & right
(arrFileLines(l),6) & ":F"
objRTC = objWSH.Run (strACLCommand , 0, True)
Set objWSH = Nothing 'clears memory
Set objWSH = CreateObject("WScript.Shell")
strACLCommand = "cmd /c echo y| CACLS d:\" &
arrFileLines(l) & " /e /g ""DomainAdminGroup"":F"
objRTC = objWSH.Run (strACLCommand , 0,
True)
Set objWSH = Nothing 'clears memory

Set objWSH = CreateObject("WScript.Shell")
strACLCommand = "cmd /c echo y| CACLS d:\" &
arrFileLines(l) & " /e /g SERVERNAME\ADMINISTRATOR:F"
objRTC = objWSH.Run (strACLCommand , 0, True)
Set objWSH = Nothing 'clears memory
End If
Next


I will be appreciating any help
 
Back
Top