469,903 Members | 1,595 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,903 developers. It's quick & easy.

File permissions

Hi all.
How can i change a file NTFS permissions?
10x, Sharon.
Nov 16 '05 #1
1 3566
' Setting NTFS permissions

' Creating Access Control Entry (ACE) object
Function SetACE(AccessMask, AceFlags, AceType, objTrustee)
Set objACE = getObject("Winmgmts:Win32_Ace").Spawninstance_
objACE.AccessMask = AccessMask
objACE.AceFlags = AceFlags
objACE.AceType = AceType
objACE.Trustee = objTrustee
Set SetACE = objACE
End Function

Wscript.Echo "Script running ..."

Set objs = GetObject("Winmgmts:").InstancesOf("Win32_AccountS ID")

For Each obj In objs
strValue = obj.Properties_("Element") ' object refrence
Set objElement = GetObject("Winmgmts:"+strValue) ' getting object
strName = objElement.Properties_("Name")
If strName = "TinaTurner" Then ' that's it
Exit For
End If
Next

' Getting SID
strValue = obj.Properties_("Setting")
Set objSid = GetObject("Winmgmts:"+strValue)
BinaryRepresentationOfSid = objSid.Properties_("BinaryRepresentation")

' Group "All"
Set objTrusteeAll = getObject("Winmgmts:Win32_Trustee").SpawnInstance_
objTrusteeAll.SID = Array(1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0)

' User GeorgeSmith
Set objTrusteeTT = GetObject("Winmgmts:Win32_Trustee").SpawnInstance_
objTrusteeTT.SID = BinaryRepresentationOfSid

' Setting NTFS permissions ...
Set Ace = SetACE(2032127, 3, 0, objTrusteeAll) ' full access

Set objSecDescriptor =
GetObject("Winmgmts:Win32_SecurityDescriptor").Spa wnInstance_
objSecDescriptor.DACL = Array(Ace)

' One folder
folderName = "C:\Data\"
Set obj = GetObject("Winmgmts:Win32_Directory='" & folderName & "'")
Set objClass = GetObject("Winmgmts:Win32_Directory")
Set objInParam =
obj.Methods_("ChangeSecurityPermissions").inParame ters.SpawnInstance_
objInParam.Option = 4 'DACL
objInParam.SecurityDescriptor = objSecDescriptor
Set objOutParams = obj.ExecMethod_("ChangeSecurityPermissions", objInParam)

Wscript.Echo folderName & " ..."
If objOutParams.ReturnValue = 0 Then
str = "... changed"
Else
str = "Error!" & vbCrLf & " ReturnValue = " & objOutParams.ReturnValue
End if
Wscript.Echo str

' Another folder
Set Ace1 = SetACE(1179817, 3, 0, objTrusteeAll) ' read
Set Ace2 = SetACE(2032127, 3, 0, objTrusteeTT) ' full

Set objSecDescriptor =
GetObject("Winmgmts:Win32_SecurityDescriptor").Spa wnInstance_
objSecDescriptor.DACL = Array(Ace1, Ace2)

folderName = "C:\Data\Accounting"
Set obj = GetObject("Winmgmts:Win32_Directory='" & folderName & "'")
Set objClass = GetObject("Winmgmts:Win32_Directory")
Set objInParam =
obj.Methods_("ChangeSecurityPermissions").inParame ters.SpawnInstance_
objInParam.Option = 4 'DACL
objInParam.SecurityDescriptor = objSecDescriptor
Set objOutParams = obj.ExecMethod_("ChangeSecurityPermissions", objInParam)

Wscript.Echo folderName & " ..."
If objOutParams.ReturnValue = 0 Then
str = "... changed"
Else
str = "Error!" & vbCrLf & " ReturnValue = " & objOutParams.ReturnValue
End if
Wscript.Echo str

Wscript.Echo "Finish"

Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

14 posts views Thread by deko | last post: by
reply views Thread by Fran Tirimo | last post: by
15 posts views Thread by David Thielen | last post: by
10 posts views Thread by John Salerno | last post: by
reply views Thread by Tim Payne | last post: by
2 posts views Thread by beary | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.