lilleman Posted January 24, 2013 Posted January 24, 2013 Hi guys! First post, but I've been lurking the forums for quite some time. I have put together a GUI script that takes input from two fields and creates folders on a server and shares them out and sets the appropriate share-permissions with SetACL.exe. Parts are from experience, and parts are from the forums. Most of the GUI parts and While - Wend are actually code I copied from here. That is why I decided to post the script here. The script does what I want it to, but there may be better ways to do it. So can you please proofread? All comments are welcome! expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <ButtonConstants.au3> #include <TreeViewConstants.au3> $font="Times New Roman" ;Include SetACL.exe, expand it to C:\Share\IT\Bin DirCreate ("C:\Share\IT\Bin\") FileInstall ("C:\Share\IT\Bin\SetACL64.exe", "C:\Share\IT\Bin\SetACL64.exe", 1) ;Server Share Create GUI $ControlPanel = GUICreate("Server Share Creation - 64Bit", 355, 215, 450, 187) $GroupBox1 = GUICtrlCreateGroup("", 14, 18, 330, 185) GUICtrlCreateLabel("Server Share Creation - 64Bit. Run as Domain Admin.", 22, 10, 280, 13) ;Share Creation Inputs GUICtrlCreateLabel("Branch number", 22, 36, 118, 18) $BnrInput = GUICtrlCreateInput("",20, 52, 118, 18) GUICtrlCreateLabel("Branch shortname", 160, 36, 118, 18) $ShnmInput = GUICtrlCreateInput("",160, 52, 118, 18) ;GUI text GUISetFont (9, 600, $font) GUICtrlCreateLabel("This version is 64Bit only.", 22, 80, 200, 17) GUICtrlCreateLabel("You are running " & @OSArch, 22, 97, 200, 17) GUISetFont (9, 400, $font) GUICtrlCreateLabel("Things may break if you run this on a 32Bit server.", 22, 114, 300, 17) GUICtrlCreateLabel("Group examples - Double check above before executing", 22, 143, 310, 17) GUICtrlCreateLabel("B-nr: sg_branch_employees_", 22, 162, 200, 17) GUISetFont (9, 600, $font) GUICtrlCreateLabel("B001", 195, 162, 100, 17) GUICtrlCreateLabel("BNWW1", 55, 180, 50, 17) GUISetFont (9, 400, $font) GUICtrlCreateLabel("Short:", 22, 180, 32, 17) GUICtrlCreateLabel("-FA Service", 110, 180, 230, 17) ;Execute button $FolderCreation = GUICtrlCreateButton("1", 290, 40, 40, 40, $BS_ICON) GUICtrlSetImage(-1, "shell32.dll", -159) GUICtrlCreateLabel("[Execute]", 286, 80, 50, 15) GUISetState(@SW_SHOW) ;Set data from inputs GUICtrlSetData($BnrInput, "") GUICtrlSetData($ShnmInput, "") ; GUI MESSAGE LOOP GuiSetState() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE _Exitcode() ;Create Folders, set permissions and Share Out Case $FolderCreation ;Get handles from inputs GUICtrlGetHandle($BnrInput) GUICtrlGetHandle($ShnmInput) ;Set new variables $sText1 = GUICtrlRead($BnrInput) $sText2 = GUICtrlRead($ShnmInput) ;Set the variable to drive\Share\Group $GrpPath = "G:\Share\group\" ;Set variable for the full path to SetACL[32/64].exe -on \\localhost\ $SAclcmd = "C:\Share\IT\Bin\SetACL64.exe -on \\localhost\" ;Set variables for the full domain\group string $BranchTlW = 'domain\sg_branch_managers_'& $sText1 $BranchEmpW = 'domain\sg_branch_employees_'& $sText1 $BranchIthk = 'domain\IT_HQTech' $BranchItst = 'domain\sg_branch_it_responsible_'& $sText1 $BranchCashS = 'domain\'& $sText2 &'-FA Cash' $BranchSrvS = 'domain\'& $sText2 &'-FA Service' $BranchStockS = 'domain\'& $sText2 &'-FA Stock' $BranchExW = 'domain\sg_branch_executive_'& $sText1 $BranchMarkW = 'domain\sg_branch_marketing_'& $sText1 $BranchAssW = 'domain\sg_branch_deputy_managers_'& $sText1 ;Create the folders RunWait(@COMSPEC & ' /c mkdir '& $GrpPath &'Assisting','', @SW_HIDE) RunWait(@COMSPEC & ' /c mkdir '& $GrpPath &'Everybody','', @SW_HIDE) RunWait(@COMSPEC & ' /c mkdir '& $GrpPath &'IT_HQ','', @SW_HIDE) RunWait(@COMSPEC & ' /c mkdir '& $GrpPath &'IT_Local','', @SW_HIDE) RunWait(@COMSPEC & ' /c mkdir '& $GrpPath &'Cash','', @SW_HIDE) RunWait(@COMSPEC & ' /c mkdir '& $GrpPath &'Service','', @SW_HIDE) RunWait(@COMSPEC & ' /c mkdir '& $GrpPath &'Stock','', @SW_HIDE) RunWait(@COMSPEC & ' /c mkdir '& $GrpPath &'Management','', @SW_HIDE) RunWait(@COMSPEC & ' /c mkdir '& $GrpPath &'Marketing','', @SW_HIDE) RunWait(@COMSPEC & ' /c mkdir '& $GrpPath &'Teamleader','', @SW_HIDE) ;Share the folders RunWait(@COMSPEC & ' /c net share Assisting='& $GrpPath &'Assisting','', @SW_HIDE) RunWait(@COMSPEC & ' /c net share Everybody='& $GrpPath &'Everybody','', @SW_HIDE) RunWait(@COMSPEC & ' /c net share IT_HQ='& $GrpPath &'IT_HQ','', @SW_HIDE) RunWait(@COMSPEC & ' /c net share IT_Local='& $GrpPath &'IT_Local','', @SW_HIDE) RunWait(@COMSPEC & ' /c net share Cash='& $GrpPath &'Cash','', @SW_HIDE) RunWait(@COMSPEC & ' /c net share Service='& $GrpPath &'Service','', @SW_HIDE) RunWait(@COMSPEC & ' /c net share Stock='& $GrpPath &'Stock','', @SW_HIDE) RunWait(@COMSPEC & ' /c net share Management='& $GrpPath &'Management','', @SW_HIDE) RunWait(@COMSPEC & ' /c net share Marketing='& $GrpPath &'Marketing','', @SW_HIDE) RunWait(@COMSPEC & ' /c net share Teamleader='& $GrpPath &'Teamleader','', @SW_HIDE) ;Set permissions, remove Everyone. ;Assisting RunWait(@COMSPEC & ' /c '& $SAclcmd &'Assisting -ot shr -actn trustee -trst "n1:Everyone;ta:remtrst"','', @SW_HIDE) RunWait(@COMSPEC & ' /c '& $SAclcmd &'Assisting -ot shr -actn ace -ace "n:'& $BranchAssW & ';p:change" -ace "n:'& $BranchExW &';p:change" -ace "n:'& $BranchTlW &';p:change" -ace "n:'& $BranchMarkW &';p:change"','', @SW_HIDE) ;Everybody RunWait(@COMSPEC & ' /c '& $SAclcmd &'Everybody -ot shr -actn trustee -trst "n1:Everyone;ta:remtrst"','', @SW_HIDE) RunWait(@COMSPEC & ' /c '& $SAclcmd &'Everybody -ot shr -actn ace -ace "n:'& $BranchEmpW & ';p:change" -ace "n:'& $BranchExW &';p:change" -ace "n:'& $BranchTlW &';p:change"','', @SW_HIDE) ;IT_HQ RunWait(@COMSPEC & ' /c '& $SAclcmd &'IT_HQ -ot shr -actn trustee -trst "n1:Everyone;ta:remtrst"','', @SW_HIDE) RunWait(@COMSPEC & ' /c '& $SAclcmd &'IT_HQ -ot shr -actn ace -ace "n:'& $BranchIthk & ';p:change" -ace "n:'& $BranchItst &';p:change"','', @SW_HIDE) ;IT_Local RunWait(@COMSPEC & ' /c '& $SAclcmd &'IT_Local -ot shr -actn trustee -trst "n1:Everyone;ta:remtrst"','', @SW_HIDE) RunWait(@COMSPEC & ' /c '& $SAclcmd &'IT_Local -ot shr -actn ace -ace "n:'& $BranchIthk & ';p:change" -ace "n:'& $BranchItst &';p:change"','', @SW_HIDE) ;Cash RunWait(@COMSPEC & ' /c '& $SAclcmd &'Cash -ot shr -actn trustee -trst "n1:Everyone;ta:remtrst"','', @SW_HIDE) RunWait(@COMSPEC & ' /c '& $SAclcmd &'Cash -ot shr -actn ace -ace "n:'& $BranchCashS & ';p:change" -ace "n:'& $BranchExW &';p:change" -ace "n:'& $BranchTlW &';p:change"','', @SW_HIDE) ;Service RunWait(@COMSPEC & ' /c '& $SAclcmd &'Service -ot shr -actn trustee -trst "n1:Everyone;ta:remtrst"','', @SW_HIDE) RunWait(@COMSPEC & ' /c '& $SAclcmd &'Service -ot shr -actn ace -ace "n:'& $BranchSrvS & ';p:change" -ace "n:'& $BranchExW &';p:change" -ace "n:'& $BranchTlW &';p:change"','', @SW_HIDE) ;Stock RunWait(@COMSPEC & ' /c '& $SAclcmd &'Stock -ot shr -actn trustee -trst "n1:Everyone;ta:remtrst"','', @SW_HIDE) RunWait(@COMSPEC & ' /c '& $SAclcmd &'Stock -ot shr -actn ace -ace "n:'& $BranchStockS & ';p:change" -ace "n:'& $BranchExW &';p:change" -ace "n:'& $BranchTlW &';p:change"','', @SW_HIDE) ;Management RunWait(@COMSPEC & ' /c '& $SAclcmd &'Management -ot shr -actn trustee -trst "n1:Everyone;ta:remtrst"','', @SW_HIDE) RunWait(@COMSPEC & ' /c '& $SAclcmd &'Management -ot shr -actn ace -ace "n:'& $BranchExW & ';p:change"','', @SW_HIDE) ;Marketing RunWait(@COMSPEC & ' /c '& $SAclcmd &'Marketing -ot shr -actn trustee -trst "n1:Everyone;ta:remtrst"','', @SW_HIDE) RunWait(@COMSPEC & ' /c '& $SAclcmd &'Marketing -ot shr -actn ace -ace "n:'& $BranchMarkW & ';p:change" -ace "n:'& $BranchExW &';p:change" -ace "n:'& $BranchTlW &';p:change"','', @SW_HIDE) ;Teamleader RunWait(@COMSPEC & ' /c '& $SAclcmd &'Teamleader -ot shr -actn trustee -trst "n1:Everyone;ta:remtrst"','', @SW_HIDE) RunWait(@COMSPEC & ' /c '& $SAclcmd &'Teamleader -ot shr -actn ace -ace "n:'& $BranchExW &';p:change" -ace "n:'& $BranchTlW &';p:change"','', @SW_HIDE) ;Message when done msgbox(64, "New Shares Created!", "You have successfully created new folders and shares. Remember to check permissions!") Exit EndSwitch WEnd Func _Exitcode() GUIDelete() Exit EndFunc
Moderators JLogan3o13 Posted January 24, 2013 Moderators Posted January 24, 2013 Hi, lilleman, welcome to the forum. I always say, if it works for you, then use it. I would, however, offer a suggestion that should speed things up for you. Creating your directories: In the section where you're creating folders, you're using this: RunWait(@COMSPEC & '/c mkdir ' & $GrpPath & 'Assisting', '', @SW_HIDE) Try using the built in DirCreate function instead so you don't have to keep calling ComSpec: DirCreate($GrpPath & 'Assisting') "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
Exit Posted January 24, 2013 Posted January 24, 2013 DirCreate("C:\Share\IT\Bin\") This would fail on my system, since there is no C: drive on it. My homedrive is G: You should use @HomeDrive App: Au3toCmd UDF: _SingleScript()
lilleman Posted January 28, 2013 Author Posted January 28, 2013 DirCreate() @HomeDrive Thanks for your suggestions! I will update my script.
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