+ Post New Thread
Results 1 to 6 of 6
How do you do....it? Thread, VBS to create folder with permissions in Technical; Does anyone have, or can anyone quickly knock up for me a script to create a folder in a number ...
  1. #1
    Admiral208's Avatar
    Join Date
    Mar 2008
    Location
    Bridgwater
    Posts
    723
    Thank Post
    176
    Thanked 63 Times in 55 Posts
    Rep Power
    40

    VBS to create folder with permissions

    Does anyone have, or can anyone quickly knock up for me a script to create a folder in a number of folders and set the permissions on that folder?

    Heres what I need...

    Our directory structure is like this,

    \\servername\userdirs\students\intakeyear\studentu sername\Files\

    I need a folder called Cakewalk set up in every one of our students Files folder with our students global security group set to deny full control.


    Im sure one of you clever people can do this in a few seconds!

    Thanks
    James

  2. #2

    jinnantonnixx's Avatar
    Join Date
    Mar 2011
    Location
    In the Calamatorium.
    Posts
    2,086
    Thank Post
    123
    Thanked 533 Times in 357 Posts
    Blog Entries
    2
    Rep Power
    336
    This should be a starting point. Look up the syntax for CACLS to make sure it does what you need. Alternatively, use ICACLS as it has more features.

    Code:
    for /d %%d in (*.) do (
    	call :setperms %%d
    )
    goto :eof
    
    :setperms
    echo Setting permission on folder %1
    cacls %1 /t /p %1:C
    echo.
    The *. assumes that this script is running from the root folder of the students - you should change it to an absolute path to be sure.

  3. Thanks to jinnantonnixx from:

    Admiral208 (21st October 2011)

  4. #3
    Admiral208's Avatar
    Join Date
    Mar 2008
    Location
    Bridgwater
    Posts
    723
    Thank Post
    176
    Thanked 63 Times in 55 Posts
    Rep Power
    40
    Thanks, dow this script create a folder?

    I cant quite understand what its supposed to be doing?

  5. #4

    jinnantonnixx's Avatar
    Join Date
    Mar 2011
    Location
    In the Calamatorium.
    Posts
    2,086
    Thank Post
    123
    Thanked 533 Times in 357 Posts
    Blog Entries
    2
    Rep Power
    336
    Apologies, it was a bit rushed. I misunderstood what you wanted to do.

    Try this.


    Code:
    set rootpath=\\servername\userdirs\students\intakeyear
    
    for /d %%d in (%rootpath%\*.) do (
    	:: for every subfolder folder in intakeyear, call a subroutine to make a new folder
    	call :makefolder %%d
    )
    goto :eof
    
    :makefolder
    echo.
    echo Creating Cakewalk subfolder in %1
    md %1\Cakewalk
    echo.
    If your parent permissions are set to deny full control, you shouldn't need to worry about inherited permissions.

    To test it does what you expect, put a 'PAUSE' statement after 'call :makefolder %%d'
    Last edited by jinnantonnixx; 21st October 2011 at 03:43 PM.

  6. Thanks to jinnantonnixx from:

    Admiral208 (21st October 2011)

  7. #5
    Admiral208's Avatar
    Join Date
    Mar 2008
    Location
    Bridgwater
    Posts
    723
    Thank Post
    176
    Thanked 63 Times in 55 Posts
    Rep Power
    40
    This is exactly what I need but this is creating a folder called cakewalk in \\servername\userdirs\students\intakeyear\studentu sername\

    I need it to create the folder in \\servername\userdirs\students\intakeyear\studentu sername\files

    The files folder is already there and has documents and other folders in it

    I also need to set the permissions on the folder to deny for the group gsgstudents


    Thanks for your help with this.

  8. #6

    jinnantonnixx's Avatar
    Join Date
    Mar 2011
    Location
    In the Calamatorium.
    Posts
    2,086
    Thank Post
    123
    Thanked 533 Times in 357 Posts
    Blog Entries
    2
    Rep Power
    336
    Oops My goof, just change the first line to
    set rootpath=\\servername\userdirs\students\intakeyear \files

    I think you wanted to deny group gsgstudents access to this folder? The cacls line sets the security. It will deny the group gsgstudents rights to the folder. If you want different rights, you can configure cacls to do what you need.

    Here's the lowdown on cacls.
    Cacls - Modify Access Control List


    ...
    So this should work.

    Code:
    set rootpath=\\servername\userdirs\students\intakeyear\files
    
    for /d %%d in (%rootpath%\*.) do (
    	:: for every subfolder folder in intakeyear, call a subroutine to make a new folder
    	call :makefolder %%d
    )
    goto :eof
    
    :makefolder
    echo.
    echo Creating Cakewalk subfolder in %1
    md %1\Cakewalk
    echo Setting permissions on folder %1\Cakewalk
    echo Y | cacls %1\Cakewalk /d gsgstudents
    echo.
    The 'echo Y | ' bit is needed as cacls asks 'Are you sure?' when you run the command. We're piping a 'Y' character to the command, effectively pressing the Y key.
    Last edited by jinnantonnixx; 21st October 2011 at 06:00 PM.



SHARE:
+ Post New Thread

Similar Threads

  1. Replies: 5
    Last Post: 1st July 2014, 09:34 AM
  2. Replies: 36
    Last Post: 5th August 2011, 08:13 AM
  3. VBS to Backup Folder and then Restore from Reg
    By simons2009 in forum Scripts
    Replies: 22
    Last Post: 2nd June 2009, 08:11 AM
  4. Replies: 6
    Last Post: 21st May 2009, 11:16 PM
  5. VB Script to create folders
    By markesmith in forum Scripts
    Replies: 2
    Last Post: 26th April 2007, 04:03 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •