startrek133 Posted August 23, 2011 Share Posted August 23, 2011 Hi Everyone, My current job uses roaming profiles, well the main directory for all these profiles got messed up by the person who used to be here .. what I need to do is figure out a way to remake this folder, so instead of hand typing everyone single users folder and setting the permission i though i try my hand at scripting it out. I have never been good at scripting so go easy on me. what i need to do is the following 1. create the users directory based on a list from AD ( this part i have figured out all ready see code below ) 2. delete "users" from having access to that folder 3. add in the "user" of that folder and give him "full control" I have read on the fourms about the "Xcals" and "acl" stuff and because i am so new to this its over my head .. so any advice would be great .. thanks .. ;Making of the folders from a txt file; #include <File.au3> Global $usrArray _FileReadToArray("test.txt", $usrArray) For $i = 1 To $usrArray[0] DirCreate("my network path"&"\"&$usrArray[$i]) Next MsgBox(0, "OK", "All Done") Link to comment Share on other sites More sharing options...
rcmaehl Posted August 23, 2011 Share Posted August 23, 2011 I believe the best way to add/remove user permissions from a directory is to pass the 'cacls' to command prompt through your script using _RunDOS() or Run() with variables obtained using Autoit or Command Prompt. http://ss64.com/nt/cacls.html <- that should be help for the 'cacls' command. My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.My Projects WhyNotWin11Cisco Finesse, Github, IRC UDF, WindowEx UDF Link to comment Share on other sites More sharing options...
startrek133 Posted August 23, 2011 Author Share Posted August 23, 2011 Thanks rcmaehl, I did find a post on the Cacls and a couple of other things and i got it all to work as long as i type in the users name when i try to use the array i get stuck .. so i have the following code with works .. RunWait(@ComSpec & ' /c c:\XCACLS.vbs "c:\username" /I "my computer"', @ScriptDir, @SW_HIDE) but if i try to use the same command and sub the "c:\username" for the array "$usrArray" it doesnt work .. ;RunWait(@ComSpec & ' /c c:\XCACLS.vbs "$usrArray" /I "my computer"', @ScriptDir, @SW_HIDE) any advice ?? Link to comment Share on other sites More sharing options...
rcmaehl Posted August 23, 2011 Share Posted August 23, 2011 Your syntax was wrong; here's the corrected version: RunWait(@ComSpec & ' /c c:\XCACLS.vbs "' & $usrArray & '" /I "my computer"', @ScriptDir, @SW_HIDE) If you have anymore problems, just let me know. My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.My Projects WhyNotWin11Cisco Finesse, Github, IRC UDF, WindowEx UDF Link to comment Share on other sites More sharing options...
startrek133 Posted August 23, 2011 Author Share Posted August 23, 2011 (edited) hhmmm thanks rcmaehl for the help .. but still not working .. that code should remove the "Inheritance" flag on the security tab of the folder but its still checked .. RunWait(@ComSpec & ' /c c:\XCACLS.vbs "' & $usrArray & '" /I Copy', @ScriptDir, @SW_HIDE) hmmm unless i wounder if i need the $usrArray[$i] ?? #include <File.au3> ;Making of the folders from a txt file; Global $usrArray _FileReadToArray("test.txt", $usrArray) For $i = 1 To $usrArray[0] DirCreate("c:\"&"\"&$usrArray[$i]) Next ; Removing the Inheritance Flag ; RunWait(@ComSpec & ' /c c:\XCACLS.vbs "' & $usrArray & '" /I Copy', @ScriptDir, @SW_HIDE) Edited August 23, 2011 by startrek133 Link to comment Share on other sites More sharing options...
guinness Posted August 23, 2011 Share Posted August 23, 2011 (edited) When posting code in the future please use the [autoit][/autoit] tags, it will help in the future when you start posting large portions of code. Simply click on the small 'A' to insert said tags. Edited August 23, 2011 by guinness UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
startrek133 Posted August 23, 2011 Author Share Posted August 23, 2011 well I tired playing around with the spacing and using the [$i] after the array and still not working .. here is my full code for everything i wanna do .. it works as long as i dont use the array , but with where i have about 200+ folders to do it would be nice to use it instead of typing everything by hand .. #include <File.au3> ;Making of the folders from a txt file; Global $usrArray _FileReadToArray("test.txt", $usrArray) For $i = 1 To $usrArray[0] DirCreate("c:\"&"\"&$usrArray[$i]) Next ; Removing the Inheritance Flag ; RunWait(@ComSpec & ' /c c:\XCACLS.vbs "c:\username" /I Copy', @ScriptDir, @SW_HIDE) ; deleting "users" from the folder; RunWait(@ComSpec & ' /c c:\XCACLS.vbs "c:\username" /E /T /R "local\Users"', @ScriptDir, @SW_HIDE) ; give admins owernship ; RunWait(@ComSpec & ' /c c:\subinacl /subdirectories "c:\username" /setowner="Administrator"', @ScriptDir, @SW_HIDE) ; give myself full controll ; RunWait(@ComSpec & ' /c c:\XCACLS.vbs "c:\username" /E /T /G domain\username:F', @ScriptDir, @SW_HIDE) ; give user full controll ; RunWait(@ComSpec & ' /c c:\XCACLS.vbs "c:\username" /E /T /G domain\username:F', @ScriptDir, @SW_HIDE) Link to comment Share on other sites More sharing options...
startrek133 Posted August 24, 2011 Author Share Posted August 24, 2011 well still at lost as to why when i change the "c:\username" to the array , that it doesn't want to set the permissions and stuff right .. played with the spacing of things last night and still didn't have any luck .. any advice ?? Link to comment Share on other sites More sharing options...
rcmaehl Posted August 24, 2011 Share Posted August 24, 2011 well still at lost as to why when i change the "c:\username" to the array , that it doesn't want to set the permissions and stuff right .. played with the spacing of things last night and still didn't have any luck .. any advice ??Yes, I'll try uploading a quick work around in a few hours from now. My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.My Projects WhyNotWin11Cisco Finesse, Github, IRC UDF, WindowEx UDF Link to comment Share on other sites More sharing options...
startrek133 Posted August 24, 2011 Author Share Posted August 24, 2011 thanks rcmaehl , there is no rush this has been messed up for months .. i know it has to be syntax error with either the array or runwait .. but i am at lose everything i have tried with different spacing and syntax errors out .. or makes the folder but doesn't set anything .. thanks for the help .. Link to comment Share on other sites More sharing options...
trancexx Posted August 24, 2011 Share Posted August 24, 2011 (edited) thanks rcmaehl , there is no rush this has been messed up for months .. i know it has to be syntax error with either the array or runwait .. but i am at lose everything i have tried with different spacing and syntax errors out .. or makes the folder but doesn't set anything .. thanks for the help ..Maybe you should consider something less demanding as hobby if it took you months not to find a solution. Crochet? Edited August 24, 2011 by trancexx ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
startrek133 Posted August 24, 2011 Author Share Posted August 24, 2011 (edited) Maybe you should consider something less demanding as hobby if it took you months not to find a solution. Crochet?it has been messed up for months , but i just got here .. only been working on this for a couple of days .. if anything is the managers fault for letting it get like this .. Edited August 24, 2011 by startrek133 Link to comment Share on other sites More sharing options...
rcmaehl Posted August 25, 2011 Share Posted August 25, 2011 (edited) @Startrek133 Sorry I didn't upload a fix yesterday I got caught up with family stuff however I am coding the script right now and it should be done within an hour or two at most. EDIT Here it is. MAKE SURE TO ADD 'END' IN CAPS WITHOUT QUOTES AT THE END OF THE FILE. expandcollapse popup#include <File.au3> ;Making of the folders from a txt file; Global $User, $Line $Line = 1 While 1 $User = FileReadLine("test.txt", $Line) If Not ($User == "END") Then DirCreate("c:\"&"\"&$User) $Line += 1 Else MsgBox(0x0, "Done", "END Encountered, Script is Done.") Exit(0) EndIf ; Removing the Inheritance Flag ; RunWait(@ComSpec & ' /c c:\XCACLS.vbs "c:\username" /I Copy', @ScriptDir, @SW_HIDE) ; deleting "users" from the folder; RunWait(@ComSpec & ' /c c:\XCACLS.vbs "c:\username" /E /T /R "local\Users"', @ScriptDir, @SW_HIDE) ; give admins owernship ; RunWait(@ComSpec & ' /c c:\subinacl /subdirectories "c:\username" /setowner="Administrator"', @ScriptDir, @SW_HIDE) ; give myself full controll ; RunWait(@ComSpec & ' /c c:\XCACLS.vbs "c:\username" /E /T /G domain\username:F', @ScriptDir, @SW_HIDE) ; give user full controll ; RunWait(@ComSpec & ' /c c:\XCACLS.vbs "c:\username" /E /T /G domain\username:F', @ScriptDir, @SW_HIDE) WEnd Edited August 25, 2011 by rcmaehl My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.My Projects WhyNotWin11Cisco Finesse, Github, IRC UDF, WindowEx UDF Link to comment Share on other sites More sharing options...
startrek133 Posted August 25, 2011 Author Share Posted August 25, 2011 thanks rcmaehl , will try it out in a little bit .. so i should be able so sub out "c:\username" the array right ?? that was my trouble before , it works fine , if i use the c:\username the trouble i was having was when i put the array in it didn't set any of the settings just made the folder .. i need the array to work because i have over 200+ folders that need fixing .. let me know .. and thanks for the help .. Link to comment Share on other sites More sharing options...
rcmaehl Posted August 25, 2011 Share Posted August 25, 2011 thanks rcmaehl , will try it out in a little bit .. so i should be able so sub out "c:\username" the array right ?? that was my trouble before , it works fine , if i use the c:\username the trouble i was having was when i put the array in it didn't set any of the settings just made the folder .. i need the array to work because i have over 200+ folders that need fixing .. let me know .. and thanks for the help ..Yeah you should if the file is like:User1user2user3etc... My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.My Projects WhyNotWin11Cisco Finesse, Github, IRC UDF, WindowEx UDF Link to comment Share on other sites More sharing options...
startrek133 Posted August 25, 2011 Author Share Posted August 25, 2011 yea the txt file , is just the user names striped out of AD .. so all i need to do then is change the "c:\username" to "$user" and that i hope will work .. going to test it now and see what happens .. thanks for all the great help !!! Link to comment Share on other sites More sharing options...
startrek133 Posted August 25, 2011 Author Share Posted August 25, 2011 well i tired every different way I know of to get that array to work and still the same issue , it will make the folder , but will not set any of the security settings or permissions .. and for some reason even putting END after the WEnd the script still runs and i have to right click on it to exit it out .. never though it would be this hard .. here are the different ways i tried the array with no luck .. RunWait(@ComSpec & ' /c c:\XCACLS.vbs ' & $User & ' /I Copy', @ScriptDir, @SW_HIDE) RunWait(@ComSpec & ' /c c:\XCACLS.vbs " & $User & " /I Copy', @ScriptDir, @SW_HIDE) RunWait(@ComSpec & ' /c c:\XCACLS.vbs & $User & /I Copy', @ScriptDir, @SW_HIDE) RunWait(@ComSpec & ' /c c:\XCACLS.vbs "&$User" /I Copy', @ScriptDir, @SW_HIDE) RunWait(@ComSpec & ' /c c:\XCACLS.vbs "$User" /I Copy', @ScriptDir, @SW_HIDE) Link to comment Share on other sites More sharing options...
hannes08 Posted August 25, 2011 Share Posted August 25, 2011 #include <file.au3> Dim $a_users Dim $s_userfolder = "D:\users\" _FileReadToArray("users.txt", $a_users) For $i = 1 To $a_users[0] DirCreate($s_userfolder & $a_users[$i] RunWait("ICACLS.exe " & $s_userfolder & $a_users[$i] & " /grant " & $a_users[$i] & ":(OI)(CI)(RX,W,DC)") Next icacls.exe is a program from windows 2008 but there's a pendant for 2003 and XP available. With this icacls syntax you create folders that cannot be deleted by the user (but the contents can). just make sure your users are not in the ACL of the parent folder (here: D:\users). Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
startrek133 Posted August 25, 2011 Author Share Posted August 25, 2011 (edited) Sorry Hannes but that didnt work either , i cant even get it to run keeps erroring out on me .. Never though it would be this hard just to make some folders and set everything right .. # include <file.au3> Dim $a_users Dim $s_userfolder = "c:\" _FileReadToArray("test.txt", $a_users) For $i = 1 To $a_users[0] DirCreate($s_userfolder & $a_users[$i] RunWait("ICACLS.exe " & $s_userfolder & $a_users[$i] & " /grant " & $a_users[$i] & ":(OI)(CI)(RX,W,DC)") Next MsgBox(0, "Done") Edited August 25, 2011 by startrek133 Link to comment Share on other sites More sharing options...
hannes08 Posted August 25, 2011 Share Posted August 25, 2011 (edited) Hi - what exactly are your errors? The script worked fine for me. What OS are you running this on? If I were you I'd consider moving the directory from the root of the C: drive. Edited August 25, 2011 by Hannes123 Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
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