Announcement

Collapse
No announcement yet.

File Permissions Scripting

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • File Permissions Scripting

    Hi my file system is as follows

    rootshare (owner - administrator, admin - full, users - read)
    |
    |
    userdirectory userdirectory userdirectory etc.....
    |
    |
    My Documents (redirect) , Application Data (redirect)



    On the userdirectory level the permissions are admin full and user full

    The subdirectories of userdirectory do not have the user as having permissions just administrator. I would like the scripting command/ script that will do the equivalent of selecting the replace permission entities on all child objects with entities shown here that apply to child objects checkbox.

    an image of what i mean for explanatory purposes


  • #2
    Re: File Permissions Scripting

    Here was my solution to the problem anyway

    '################################################# #########################################
    'SCRIPT TO ADD USER TO PERMISSIONS
    'CREATED BY *************
    '################################################# #########################################

    redim FolderList(0) 'ReDim statement allows you to formally declare, and to later redeclare as
    'many times as you need, the size (and hence the memory space allocation)
    'for a dynamic array

    ' Create a shell for cmd and CACLS
    Set objShell = CreateObject("Wscript.Shell")

    'DEFINE ROOT FOLDER
    FolderList(0) = "d:\userRedirect"
    msgbox "RUNNING ..."

    'FOR ALL SUBDIRECTORIES OF ROOT
    FolderIndex = 0
    Do Until FolderIndex > Ubound(FolderList)

    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f = fso.GetFolder(folderList(folderindex))

    If f.subfolders.count > 0 Then
    For Each folder In f.subFolders
    intRunError = objShell.Run("%COMSPEC% /k echo off & cd /D d: & cd userRedirect & CACLS Administrator /T /E /C /P Administrator:F")
    objShell.Run("%COMSPEC% /k echo off & cd /D d: & cd userRedirect & CACLS " & folder.name & " /T /E /C /P " & folder.name & ":c")
    '#################################
    'ATTEMPTING TO RUN THESE COMMANDS
    'ECHO OFF
    'cd /D d:
    'cd userRedirect 'current folder is then d:\userRedirect the share
    'cacls %username% /t /e /c /p %username%:c
    '#################################

    If intRunError <> 0 Then
    msgbox "Error assigning permissions for user " & folder.name
    End If
    Next

    End If
    'INCREMENT TO NEXT FOLDER
    FolderIndex = FolderIndex + 1
    Loop
    '################################################


    The next stage of this script would be to revoke all other permissions first on the files

    I would first run a shell cacls folder.name > permissions.txt

    This file would contain all current permissions on file

    with a little bit of string manipulation I could get all the usernames so Administrator, Users, 30110110 etc

    I would then use the CACLS /R %username% for all usernames found on permissions list. Then I would continue to add my custom permissions as above.

    As the old saying goes, If you want something done right, do it yourself.

    Comment

    Working...
    X