Apply Group Security to newly created folder

Discussion in 'Scripting' started by John R, Jan 20, 2006.

  1. John R

    John R Guest

    I am using the file system object in VBA to create a folder and move
    confidential documents to the folder. I need to secure the folder by
    assigning access to a specific group. I was told this can be done using a
    script. I have searched and cannot find sample code on how to accomplish
    this. I appreciate any help finding what I need
    John R, Jan 20, 2006
    1. Advertisements

  2. John R

    Umesh Thakur Guest

    'Use the script below to apply permission on given folder...

    dim Wshshell, fso
    Set Wshshell=CreateObject("WScript.Shell")
    Set fso = CreateObject("Scripting.FileSystemObject")

    'Folder on which permissions will be applied,

    'Path of cacls.exe, it is found at below mentioned location on XP Machines.
    caclsPath = "c:\Windows\System32\cacls.exe"

    If (fso.FileExists(caclsPath)) Then
    If (fso.FolderExists(folderPath)) Then & " " & folderPath & " /t /E /P
    'users:C means "Users" group will be assigned Change permission. Refer
    to CACLS help (cacls /? at command prompt) for more info.
    if oExec <> 0 then
    wscript.echo "Unable to set permissions.Error: " & err.number & ":" &
    wscript.quit oExec
    wscript.echo "Successfully set permissions on folder." 'comment this line
    if you don't want to display the message,
    end if
    wscript.echo "Unable to set permissions, source folder not found. "
    wscript.quit -1
    End If
    wscript.echo "Unable to set permissions, CACLS.EXE was not found."
    wscript.quit -1
    End If
    Umesh Thakur, Jan 23, 2006
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.