473,372 Members | 1,248 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

File permissions

Hi all.
How can i change a file NTFS permissions?
10x, Sharon.
Nov 16 '05 #1
1 3726
' 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: deko | last post by:
Do I need to use flock() when reading a file into an array? It's possible that the file in question could be open at the time the file('filename') request is made. I realize flock() is required...
5
by: Phil Powell | last post by:
print_r(is_file("$logPath/$logFileName")); // RETURNS 1 unlink("$logPath/$logFileName"); // RETURNS WARNING: PERMISSION DENIED This code should tell me that the file located at...
0
by: Fran Tirimo | last post by:
I am developing a small website using ASP scripts to format data retrieved from an Access database. It will run on a Windows 2003 server supporting FrontPage extensions 2002 hosted by the company...
2
by: Fran Tirimo | last post by:
I am developing a small website using ASP scripts to format data retrieved from an Access database. It will run on a Windows 2003 server supporting FrontPage extensions 2002 hosted by the company...
15
by: David Thielen | last post by:
Hi; My ASP.NET app (C# calling J# under .net 2.0) creates a png file in a subdirectory to display as part of the created page. However, the bitmap will not display due to a security violation. ...
10
by: John Salerno | last post by:
I always read about how you need to set certain file permissions (for cgi files, for example), but it's never been clear to me *how* you do this. I know you can run the line chmod 755...
7
by: sprash | last post by:
Newbie question: I'm trying to determine if a file physically exists regardless of the permissions on it Using File.Exists() returns false if it physically exists but the process does not...
0
by: Tim Payne | last post by:
I have an odd permissions issue with uploading files to a windows 2003 server. I have a reasonably unusual setup. We have a php website, running through IIS that was written to use mod_rewrite....
1
by: chrisj | last post by:
I'm using freeASPupload and got some assistance integrating to a Member script. It works successfully. In this modified version there are two groups that use this upload script. Members of one...
2
by: beary | last post by:
Hello everyone, I posted this in unix/linux but it received no replies, so I assume it was the wrong forum. I'm trying here. I'm in way over my head with file permissions. The directory and...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.