Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script to change permissions

Status
Not open for further replies.

james1990

Technical User
Jan 21, 2005
14
GB
Hi all,

I'll jump straight to the point.....I'm trying to create a vb script which sets permissions on a folder and everything beneath it in the tree.

I need to give two groups of users modify control, these are 'Global Staff' and 'Global Students'.

I have a script which changes permissions on the folder, but I'm not sure how to tell it to apply to everything below it in the tree.

Here is the script:

===========================================

Option Explicit
Dim FolderToChange, FolderToChangePath

FolderToChange = ("""C:\solidworks data\browser""")
FolderToChangePath = ("C:\solidworks data\browser")
'WScript.Echo FolderToChange

Call ChangePerm(FolderToChange)


Function ChangePerm(FolderToChange)
'WScript.Echo ("function1")
Dim objfso, WshShell, Result, Command, objShell, Command2
Result=False
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objfso.FolderExists(FolderToChangePath) Then
'WScript.Echo ("inside if")
Set objShell = CreateObject("Wscript.Shell")
Command = ("%COMSPEC% /c Echo Y| cacls " & FolderToChange & " /e /g /a /d y /r ""Global Staff"":c")
objShell.Run (Command)
Command2 = ("%COMSPEC% /c Echo Y| cacls " & FolderToChange & " /e /g ""Global Students"":c")
objShell.Run (Command2)
Result = True
End If
ChangePerm = Result
End Function
============================================


Thanks in advance!

James
 
A brute force approach might be to create a collection of folders and set the permissions for each one using some code simliar to the following example, inserted in your script after you check to see if the folder exists and create the shell.

Set objFolder=objFSO.GetFolder(FolderToChangePath)
'Do stuff, like set permissions for FolderToChange (or use objFolder.path)
Set colFolders=objFolder.SubFolders
For each objFolder in colFolders
'Do stuff again for objFolder.path
Next


There is probably an easier way, but this seems like it might work if nothing else...
 
Isn't there a /t switch for the Cacls command that will include all the subfolders?
 
Also look at the iCACLs command (included with 2003 SP-2), because it can control the inheritance flag, where CACLs and xCACLs cannot.

PSC

Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo! --Mr. The Plague, from the movie "Hackers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top