Link to home
Start Free TrialLog in
Avatar of B1izzard
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.FileSystemObject")
Set wshShell = wscript.CreateObject("WScript.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"
Avatar of prashanthd
prashanthd
Flag of India image

Try following, the = operator is case sensitive while comparing strings so "docs" is not equal to "DOCS".
Set objFS = CreateObject("Scripting.FileSystemObject")
Set wshShell = WScript.CreateObject("WScript.Shell")
strFolder = "C:\backup"
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 LCase(strDir.Name) = lcase("docs") Then
            WScript.Echo "cmd /k xcacls " &Chr(34) &strDir &Chr(34) &" /T /F /S /E /G SHOP:F"
            wshShell.run "cmd /k xcacls " &Chr(34) &strDir &Chr(34) &" /T /F /S /E /G SHOP:F"
        End If
    Next
End Sub
ScanDir objFolder

Open in new window

Avatar of B1izzard
B1izzard

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
Avatar of prashanthd
prashanthd
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Worked great!  Thanks.  It solved my problem and got the permission issue straightened out.