alunmjones Posted June 9, 2011 Posted June 9, 2011 (edited) I’m going through all of our kids folders one by one and changing the permissions, I’ve been having problems with something on the network changing the permissions on random student home folders to Everyone: delete and nothing else. I’m going through them and setting the Advanced Security settings for the folder manually, there has to be an easy way to set them. I did think about using Cacls or Xcacls as i have done in the past but after looking at it, it’s not granular enough for what I need, the settings are far to broad. Before I go and try and develop my own script or something to do it I thought I’d ask. ---- Things it should do ---- Start at the top folder (Year Folder) and look down every folder contained within. Each Folder is a new Home folder of a new user Needs to look at the folder name and use it later Re-set the file permissions to inherit from above and remove the permissions currently set for the user (I have already made the changes to permissions the files inherit from the primary folder, that was easy) Set a new permission based on the folder name (this is where cacls/xcacls won’t work) The permission needs to be Allow everything except, Change Permissions and Take Ownership it should then propagate this down the home folder tree and move on to the next folder till it does not have any folders left. ---- ---- Im not looking forward to doing it manually, i am thinking it will fix the problem im having. Can anyone point me in the right direction? I don’t know how to get vbscript to access the advanced file permissions, that’s really what i need help with, I think I can get it to do everything else, propagation might be a problem though Any help would be appreciated, thanks Edited June 9, 2011 by alunmjones
JMBates Posted April 11, 2012 Posted April 11, 2012 Does anyone have any scripts to do this? I am in desperate need for the same script.
themightymrp Posted April 11, 2012 Posted April 11, 2012 I have cobbled this together by ripping out parts of a script I have and altering bits. With some testing it should work.... I think :/ Copy and paste into notepad and save as a .vbs ' Map a temporary network drive to year folder (root) Set objNetwork = CreateObject("WScript.Network") objNetwork.MapNetworkDrive "Q:", "\\server\share\year" ' Dump the list of folder names into a CSV file for use later ' To do this open a command prompt and use DIR command intshort = 100 strDump = "dir /b >c:\yearx.csv" objShell.Run "cmd" Wscript.Sleep intshort objShell.SendKeys strDump objShell.SendKeys "{ENTER}" Wscript.Sleep intshort objShell.SendKeys "exit" objShell.SendKeys "{ENTER}" ' Define a variable to use for the folder name Dim strFolderName ' Read the contents of newly created CSV into an array Const ForReading = 1 Set objFSO = Nothing set objTextFile = Nothing Set objFSO = CreateObject("Scripting.FileSystemObject") Set objTextFile = objFSO.OpenTextFile("C:\yearx.csv", ForReading) Do While objTextFile.AtEndOfStream <> True strNextLine = objTextFile.Readline arrUSERData = split(strNextLine, ",") strFolderName = arrUSERData(0) ' Use xcacls to set NTFS permissions ' This opens a command prompt and feeds the xcacls and variable into the line ' First command removes the old setting, second one creates the new one intshort = 100 Set objShell = CreateObject("WScript.Shell") strPart1 = "xcacls q:\" strPart2 = " /R " strPart3 = " /T /E /C /G " objShell.Run "cmd" Wscript.Sleep intshort objShell.SendKeys strPart1 & strFolderName & strPart2 & strFolderName objShell.SendKeys "{ENTER}" objShell.SendKeys strPart1 & strFolderName & strPart3 & strFolderName objShell.SendKeys "{ENTER}" Wscript.Sleep intShort ' Clear the variable for the next pass through set strFolderName = Nothing Loop ' Close text file objTextFile.Close ' Remove the temporary network drive DriveLetter1 = "Q:" objNetwork.RemoveNetworkDrive Driveletter1, "True", "True"
mac_shinobi Posted April 11, 2012 Posted April 11, 2012 I have cobbled this together by ripping out parts of a script I have and altering bits. With some testing it should work.... I think :/ Copy and paste into notepad and save as a .vbs ' Map a temporary network drive to year folder (root) Set objNetwork = CreateObject("WScript.Network") objNetwork.MapNetworkDrive "Q:", "\\server\share\year" ' Dump the list of folder names into a CSV file for use later ' To do this open a command prompt and use DIR command intshort = 100 strDump = "dir /b >c:\yearx.csv" objShell.Run "cmd" Wscript.Sleep intshort objShell.SendKeys strDump objShell.SendKeys "{ENTER}" Wscript.Sleep intshort objShell.SendKeys "exit" objShell.SendKeys "{ENTER}" ' Define a variable to use for the folder name Dim strFolderName ' Read the contents of newly created CSV into an array Const ForReading = 1 Set objFSO = Nothing set objTextFile = Nothing Set objFSO = CreateObject("Scripting.FileSystemObject") Set objTextFile = objFSO.OpenTextFile("C:\yearx.csv", ForReading) Do While objTextFile.AtEndOfStream <> True strNextLine = objTextFile.Readline arrUSERData = split(strNextLine, ",") strFolderName = arrUSERData(0) ' Use xcacls to set NTFS permissions ' This opens a command prompt and feeds the xcacls and variable into the line ' First command removes the old setting, second one creates the new one intshort = 100 Set objShell = CreateObject("WScript.Shell") strPart1 = "xcacls q:\" strPart2 = " /R " strPart3 = " /T /E /C /G " objShell.Run "cmd" Wscript.Sleep intshort objShell.SendKeys strPart1 & strFolderName & strPart2 & strFolderName objShell.SendKeys "{ENTER}" objShell.SendKeys strPart1 & strFolderName & strPart3 & strFolderName objShell.SendKeys "{ENTER}" Wscript.Sleep intShort ' Clear the variable for the next pass through set strFolderName = Nothing Loop ' Close text file objTextFile.Close ' Remove the temporary network drive DriveLetter1 = "Q:" objNetwork.RemoveNetworkDrive Driveletter1, "True", "True" I would avoid using sendkeys where possible, if your email client or something else pops up half way through running said script it could get you into trouble
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now