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"
B1izzardAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

prashanthdCommented:
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

0
B1izzardAuthor Commented:
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?
0
prashanthdCommented:
Try the following...
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 /c xcacls " &Chr(34) &strDir &Chr(34) &" /T /F /S /E /G SHOP:F"
        End If
    Next
End Sub
ScanDir objFolder

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Kamaraj SubramanianApplication Support AnalystCommented:
0
B1izzardAuthor Commented:
Worked great!  Thanks.  It solved my problem and got the permission issue straightened out.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.