B1izzard
asked on
Script to change folder permissions
I have a script I am working on that must:
1. Search for a folder by name. In this example the folders name is Docs
2. Must change the permissions so the SHOP group is propagated down through the Docs folder, all subfolders, and all files using Xcacls.
The Xcacls command by itself works OK to create the groups when I run it manually at the command prompt, but when I try to run the script as a whole, it doesn't quite work right to find a Docs folder AND propagate the permissions. Here is what I have:
Set objFS = CreateObject("Scripting.Fi leSystemOb ject")
Set wshShell = wscript.CreateObject("WScr ipt.Shell" )
strFolder = "C:\Master"
Set objFolder = objFS.GetFolder(strFolder)
Sub ScanDir (objFolder)
For Each strDir In objFolder.SubFolders
ScanDir(strDir)
WScript.Echo strDir.Name & "," & strDir.Path &","&strDir.Size
If strDir.Name = "DOCS" Then
wshShell.run "xcacls " &chr(34) &strDir &chr(34) &" /T /F /S /E /G SHOP:F"
End If
Next
End Sub
ScanDir objFolder
************************** ********** ********** ****
Also, one odd thing I notice is when I put in:
If strDir.Name = "Docs", then I get the following error:
c:\master\script2.vbs(12, 4) (null): The system cannot find the file specified.
However, when I put it in all CAPS, I do not get the error:
If strDir.Name = "DOCS"
1. Search for a folder by name. In this example the folders name is Docs
2. Must change the permissions so the SHOP group is propagated down through the Docs folder, all subfolders, and all files using Xcacls.
The Xcacls command by itself works OK to create the groups when I run it manually at the command prompt, but when I try to run the script as a whole, it doesn't quite work right to find a Docs folder AND propagate the permissions. Here is what I have:
Set objFS = CreateObject("Scripting.Fi
Set wshShell = wscript.CreateObject("WScr
strFolder = "C:\Master"
Set objFolder = objFS.GetFolder(strFolder)
Sub ScanDir (objFolder)
For Each strDir In objFolder.SubFolders
ScanDir(strDir)
WScript.Echo strDir.Name & "," & strDir.Path &","&strDir.Size
If strDir.Name = "DOCS" Then
wshShell.run "xcacls " &chr(34) &strDir &chr(34) &" /T /F /S /E /G SHOP:F"
End If
Next
End Sub
ScanDir objFolder
**************************
Also, one odd thing I notice is when I put in:
If strDir.Name = "Docs", then I get the following error:
c:\master\script2.vbs(12, 4) (null): The system cannot find the file specified.
However, when I put it in all CAPS, I do not get the error:
If strDir.Name = "DOCS"
ASKER
Thank you. This works. Only one problem. There are hundreds of windows that will appear when executing this. How do I prevent the pop ups?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
are you using xcacls.vbs ?
http://support.microsoft.com/kb/825751
http://vanstechelman.eu/windows/usage_of_xacls_vbs
http://support.microsoft.com/kb/825751
http://vanstechelman.eu/windows/usage_of_xacls_vbs
ASKER
Worked great! Thanks. It solved my problem and got the permission issue straightened out.
Open in new window