473,491 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Setting Read Only Permissions

I am trying to set permissions on a folder programmatically, and have
success fully used the code below for knowledge base article 266461 : How
To: Programmatically Set NTFS File System Folder Permissions Using Microsoft
Visual Basic . NET

However I need to set the permissions to Read Only rather than Full Control,
can any one help me with this.

Dim objADsSec As ADsSecurity

Dim objSecDes As SecurityDescriptor

Dim objDAcl As AccessControlList

Dim objAce As Object

Dim objAce1 As AccessControlEntry

Dim objAce2 As AccessControlEntry

Dim objSId As ADsSID

Dim objSIdHex As Object

objADsSec = New ADsSecurity

objSecDes = CType(objADsSec.GetSecurityDescriptor("FILE://" & vPath),
SecurityDescriptor)

objDAcl = CType(objSecDes.DiscretionaryAcl, AccessControlList)

objSId = New ADsSID

objSId.SetAs(ADSSECURITYLib.ADS_SID_FORMAT.ADS_SID _SAM, CStr(UserName))

objSIdHex = objSId.GetAs(ADSSECURITYLib.ADS_SID_FORMAT.ADS_SID _SDDL)

' Add a new objAce so that the User has Full Control on NTFS Files.

objAce1 = New AccessControlEntry

objAce1.Trustee = CStr(objSIdHex)

objAce1.AccessMask = ActiveDs.ADS_RIGHTS_ENUM.ADS_RIGHT_GENERIC_ALL

objAce1.AceType = ActiveDs.ADS_ACETYPE_ENUM.ADS_ACETYPE_ACCESS_ALLOW ED

objAce1.AceFlags = ActiveDs.ADS_ACEFLAG_ENUM.ADS_ACEFLAG_INHERIT_ACE Or
ActiveDs.ADS_ACEFLAG_ENUM.ADS_ACEFLAG_INHERIT_ONLY _ACE Or 1

objDAcl.AddAce(objAce1)

' Add a new objAce so that the User has Full Control on NTFS Folders.

objAce2 = New AccessControlEntry

objAce2.Trustee = CStr(objSIdHex)

objAce2.AccessMask = ActiveDs.ADS_RIGHTS_ENUM.ADS_RIGHT_GENERIC_ALL

objAce2.AceType = ActiveDs.ADS_ACETYPE_ENUM.ADS_ACETYPE_ACCESS_ALLOW ED

objAce2.AceFlags = ActiveDs.ADS_ACEFLAG_ENUM.ADS_ACEFLAG_INHERIT_ACE Or 1

objDAcl.AddAce(objAce2)

objSecDes.DiscretionaryAcl = objDAcl

' Set Permissions on the NTFS folder.

objADsSec.SetSecurityDescriptor(objSecDes)

Thanks

Phil

Nov 21 '05 #1
0 1291

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2314
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...
1
5401
by: byrocat | last post by:
I've got a tool that accesses syslogins to pick up some information. When I run the tool, I get the error message that sasys that my login does not have sufficient permissions to read syslogins....
0
2315
by: Praveen | last post by:
Hello. I am writing some code that accepts a DFS Link and Username and grants that User permissions to the physical directory that the DFS Link corresponds to. I am using the System.Management...
5
2143
by: Mark | last post by:
Hi All, This maybe a really simple question but I need some help. I have been having problems with security and thanks to the help received from a reply to an earlier post, I have found a...
1
1955
by: Bob Sanderson | last post by:
I want to put an Access database back end on a network server so that it can be shared by several users. I plan to use the built-in Access security to set permissions for the database but am...
1
2079
by: Kevin Burton | last post by:
I am using aspnet_setreg but the permissions that it sets the registry to leave the application unable to access the information. I want to add the ASPNET account on the machine that our...
2
313
by: Phil Hey | last post by:
I am trying to set permissions on a folder programmatically, and have success fully used the code below for knowledge base article 266461 : How To: Programmatically Set NTFS File System Folder...
10
2587
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...
0
860
by: Jesse | last post by:
I've got two directories on the same server, like this: \Public \Private I want to move the directory \Private\myDir into \Public. After I move it, I
5
2155
by: daokfella | last post by:
I have a custom web.config section similar to the following: <CustomAuthSettings attr1="" attr2=""> <Locations RedirectUrl="Invalid.aspx"> <add Path="test.aspx" Roles="1,2,3" Permissions="4,5,6"...
0
7118
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6980
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6862
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7364
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5452
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4579
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3087
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
637
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
282
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.