Jump to content

Script to alter security on same folder in multiple folders


Recommended Posts

Posted

I need a script (pref VB) to change permissions on a folder in multiple folders.

 

Example, imagine users home directory, so a folder contains all the users. Each user has a folder insiide their home driectory called 'examples'. I need a script to search for that folder inside each users home directory and change the permissios to 'read, list folder contents'

 

Can this be done?

 

This is not being done on users home directories but this was the best example i could give.

 

Or imagine their are 10 folders named 1 to 10. inside each folder are 5 folders named A,B,C,D and E. I want a script to search for the folder named 'D' and change the permission on that folder only.

  • 2 weeks later...
Posted

Well the there's a vbs version of xcacls which will let you modify NTFS permissions. I use it to modify local directory permissions on workstations at machine start up.

 

As for it looking for all folders named 'D' in a directory tree, It can't do that itself, but it's a start.

 

Link http://support.microsoft.com/kb/825751

 

 

Mike.

 

Edit:

 

Cobbled together this bit of code which examines the directory tree under the specified directory, it then compares the all the folder and subfolder names to the specified folder name. If it finds a match it then calls the XCACLS.VBS script using the full folder path and the specified options. I've not tested this, so it may need some tweaking. I know the directory search bit works, just the line that calls XCACLS might need some adjusting.

 

Set objShell = CreateObject("WScript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")

ShowSubfolders FSO.GetFolder("C:\SPECIFY\START\FOLDER")

Sub ShowSubFolders(Folder)
   For Each Subfolder in Folder.SubFolders
       if Subfolder.Name = "FOLDERNAME" then 
runline = "c:\xcacls.vbs " & subfolder.Path & " /E /G etc. etc."
objShell.Run runline
End if
       ShowSubFolders Subfolder
   Next
End Sub

 

Hope that helps,

 

Mike.

  • 4 years later...
Posted (edited)

Hi Maniac (and others),

 

Old post, but still of value to me for it aims to do exactly what I need. I can't however get it to fully work and wondered if you (or anyone else) can help me further.

 

I can confirm the script on itself is working, as far as the searching for folders goes. I can also confirm the runline needs some tweaking.

 

What I got so far is this (I entered my foldernames into your script and started tweaking the runline):

 

Set objShell = CreateObject("WScript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")

ShowSubfolders FSO.GetFolder("J:\7. IT\9. IT only\TEMP\Test\TEST VB SCRIPT")

Sub ShowSubFolders(Folder)
   For Each Subfolder in Folder.SubFolders
       if Subfolder.Name = "d" then
   runline = "cscript.exe c:\windows\xcacls.vbs " & subfolder.Path & " /I COPY"
   objShell.Run runline
   End if
       ShowSubFolders Subfolder
   Next
End Sub

 

As you can see i added cscript.exe at the beginning, for that seems to be requiered by xcacls.vbs

I created a directory structure for testing purposes. When running the script, I see a certain number of cmd-windows popup and disappear again, 1 for each subfolder named "d" found, so the searchin for folders named "d" works. The runline however, does not do what I expect/want. It somehow seems to have a hard time dealing with subfolder.Path. The action (in this case remove inheritance, copy security settings) is not carried out.

 

When I enter the runline in a cmd-window and use a real directorypath instead of subfolder.path, inheritance is in fact removed and security settings are being copied.

 

Besides removing inheritance I as well want to add permissions; but first I got to get this working in it's simplest form, before I go deeper.

 

I already tried runline = "cscript.exe c:\windows\xcacls.vbs " & "subfolder.Path" & " /I COPY", thinking the spaces in the path might be the problem, to no avail.

 

J: is a network share. I as well tried the script locally on the dataserver (with edited folder paths), same result.

 

Any ideas/suggestions ?

 

Regards,

 

A.

Edited by Adm1n
Posted

Problem solved. I added a messagebox which displayed the contents of the runline. This displayed the full command, and the problem was obvious right away. My folderpath which contains spaces was printed without quotes. Added quotes et voila.... the working code:

 

Set objShell = CreateObject("WScript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")

ShowSubfolders FSO.GetFolder("J:\7. IT\9. IT only\TEMP\Test\TEST VB SCRIPT")

Sub ShowSubFolders(Folder)
   For Each Subfolder in Folder.SubFolders
       if Subfolder.Name = "d" then
           rem Call MsgBox("cscript.exe c:\windows\xcacls.vbs """ &  Subfolder.Path & """ /I COPY" , vbOKOnly + vbInformation, "My  Script Title")
           runline = "cscript.exe c:\windows\xcacls.vbs """ & Subfolder.Path & """ /I COPY"
           objShell.Run runline
       End if
   ShowSubFolders Subfolder
   Next
End Sub

 

Now I still must complete the runline to do exactly what I want (remove inheritance and set specific permissions), but at least I got a working script now to start from.

 

Regards,

 

Adm1n

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...