+ Post New Thread
Results 1 to 9 of 9
Scripts Thread, Script to share multiple folders in Coding and Web Development; Hey all, I'm in need of a script that I can use to share alot of folders all in one ...
  1. #1
    originofsymmetry's Avatar
    Join Date
    Jun 2007
    Posts
    182
    Thank Post
    9
    Thanked 13 Times in 11 Posts
    Rep Power
    12

    Script to share multiple folders

    Hey all, I'm in need of a script that I can use to share alot of folders all in one directory. I have the following for example:
    net share <sharename>=<path> /CACHE:no /GRANT:domain\user,READ|CHANGE|FULL

    but obviously this requires me to type in each folder name, anyone have a script for automating this? Any help appreciated.

  2. IDG Tech News

  3. #2


    Join Date
    Feb 2007
    Location
    Northamptonshire
    Posts
    4,431
    Thank Post
    327
    Thanked 726 Times in 654 Posts
    Rep Power
    201
    For each loop?

  4. #3

    SYNACK's Avatar
    Join Date
    Oct 2007
    Posts
    7,558
    Blog Entries
    9
    Thank Post
    444
    Thanked 1,910 Times in 1,624 Posts
    Rep Power
    458
    how good are you with VBS?

    enumerate all subfolders in a folder:
    Scripting Files and Folders using VBScript

    use a for each loop that runs a command for each returned folder name
    How to: Execute a file/program in VBScript - CRM Developer

    Code:
    dim folderpath
    folderpath = "C\folder"
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFolder = objFSO.GetFolder(folderpath)
    Set colSubfolders = objFolder.Subfolders
    For Each objSubfolder in colSubfolders
        Wscript.Echo objSubfolder.Name
        Run "net share " & objSubfolder.Name & "=" & folderpath & "\" & objSubfolder.Name & " /CACHE:no /GRANT:domain\user,READ|CHANGE|FULL"
    Next
    Sub Run(ByVal sFile)
    Dim shell
    
        Set shell = CreateObject("WScript.Shell")
        shell.Run Chr(34) & sFile & Chr(34), 1, false
        Set shell = Nothing
    End Sub
    
    Haven't tested it but it should be a good start if it does not work straight away.
    Last edited by SYNACK; 20th August 2008 at 04:53 PM.

  5. #4


    Join Date
    Jul 2007
    Location
    Rural heck
    Posts
    2,602
    Thank Post
    111
    Thanked 423 Times in 345 Posts
    Rep Power
    120
    Other way to do this if you're not very confident of your scripting it to use a spread. Use the CONCATENATE function to combine the variables with the rest of the code.

  6. #5

    Ric_'s Avatar
    Join Date
    Jun 2005
    Location
    London
    Posts
    7,623
    Thank Post
    96
    Thanked 685 Times in 528 Posts
    Rep Power
    158
    Why don't you just share the root of all these folders? With the correct permissions, people would only be able to get into what they should be able to anyway.

    If mapping drives off these shares, it is possible to map a subdirectory of a share as a drive letter too.

  7. #6
    box_l's Avatar
    Join Date
    May 2007
    Location
    Herefordshire
    Posts
    338
    Thank Post
    52
    Thanked 68 Times in 56 Posts
    Rep Power
    22
    i use this:

    FOR /D %%G IN (*.*) DO NET SHARE "%%G=%CD%\%%G" /GRANT:Everyone,FULL /CACHE:None

    yours might look like this:

    FOR /D %%G IN (*.*) DO net share <sharename>=<path> /CACHE:no /GRANT:domain\user,READ|CHANGE|FULL

    run this bat file from the folder containing folders to be shared.
    or *.* probably will not work

    BoX

  8. 2 Thanks to box_l:

    originofsymmetry (22nd August 2008), simpsonj (16th September 2010)

  9. #7
    originofsymmetry's Avatar
    Join Date
    Jun 2007
    Posts
    182
    Thank Post
    9
    Thanked 13 Times in 11 Posts
    Rep Power
    12
    Thanks for these scripts guys, will try them out when I get home tonight

  10. #8
    originofsymmetry's Avatar
    Join Date
    Jun 2007
    Posts
    182
    Thank Post
    9
    Thanked 13 Times in 11 Posts
    Rep Power
    12
    Quote Originally Posted by box_l View Post
    i use this:

    FOR /D %%G IN (*.*) DO NET SHARE "%%G=%CD%\%%G" /GRANT:Everyone,FULL /CACHE:None

    yours might look like this:

    FOR /D %%G IN (*.*) DO net share <sharename>=<path> /CACHE:no /GRANT:domain\user,READ|CHANGE|FULL

    run this bat file from the folder containing folders to be shared.
    or *.* probably will not work

    BoX
    Thanks for that BoX, worked a treat

  11. #9
    box_l's Avatar
    Join Date
    May 2007
    Location
    Herefordshire
    Posts
    338
    Thank Post
    52
    Thanked 68 Times in 56 Posts
    Rep Power
    22
    no problem.

  12. Thanks to box_l from:

    simpsonj (16th September 2010)

SHARE:
+ Post New Thread

Similar Threads

  1. Script to delete certain folders
    By Pumaedition in forum Scripts
    Replies: 4
    Last Post: 22nd April 2008, 10:08 PM
  2. Replies: 1
    Last Post: 1st November 2007, 01:31 AM
  3. Replies: 15
    Last Post: 19th September 2007, 10:46 PM
  4. VB Script to create folders
    By markesmith in forum Scripts
    Replies: 2
    Last Post: 26th April 2007, 03:03 PM
  5. Replies: 8
    Last Post: 1st February 2007, 09:42 AM

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
  •