SetACL - example 01

Author Mattias Andolfsson on February 19, 2010 | Print | Bookmark
Option Explicit

Dim objACL
Dim path, user, permission
Dim isDomain, isWINDOWS_FileSystemPermission

isDomain = 1
path = "C:\Files\TEMP\Testing"
user = "user"
permission = "change"  'Windows GUI = Modify

isWINDOWS_FileSystemPermission = WINDOWS_FileSystemPermission(isDomain, path, user, permission)
WScript.Echo "Permissions is in state: "& isWINDOWS_FileSystemPermission

Function WINDOWS_FileSystemPermission(isDomain, path, user, permission)
  Dim isOK
    WINDOWS_FileSystemPermission = False

  Set objACL = CreateObject("SetACL.SetACLCtrl.1")
    objACL.SetObject path, 1
    objACL.SetAction 1

    If isDomain = 1 Then
      ' Assign permissions for Domain User
      objACL.AddACE "DOMAIN\"& user, False, "change", 0, false, 1, 1
    Else 
      ' Assign permissions for Local User
      objACL.AddACE "LOCALHOST\" & user, False, "read,change", 0, false, 1, 1
    End If

  objACL.Run
    WINDOWS_FileSystemPermission = True

  Set objACL= Nothing
End Function

Was this article helpful?

Yes No

Category: Scripting, VBScript, SetACL

Last updated on April 20, 2010 with 2324 views