473,504 Members | 13,830 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Programmatically Set NTFS File System Folder Permissions

I am getting the error "The security ID structure is invalid." When running
this code.

Sub SetPermissions(ByRef vPath As String, ByVal UserName As String)
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

UserName = "molnarc"
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) '<-- Error happens here

End Sub

I have even tried this and still get the error.

Sub SetPermissions(ByRef vPath As String, ByVal UserName As String)
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

UserName = "molnarc"
objADsSec = New ADsSecurity
objSecDes = CType(objADsSec.GetSecurityDescriptor("FILE://" &
vPath), SecurityDescriptor)
objADsSec.SetSecurityDescriptor(objSecDes) '<-- Error happens here

end sub

Any clue as what i could be doing wrong?


Jul 21 '05 #1
0 4626

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

Similar topics

7
2544
by: Kim Lots | last post by:
Hi Sorry to disturb you again but i really like to know what's the NTFS folder permissions on a "virtual directory" folder for a public webserver iis 5.x running ASP 3.0 with an Access DB on a...
8
6630
by: noe | last post by:
Hello all devs!! I’m a student and I’m developing my Final Project in the University. I have to develop a driver for Windows XP that work so: I have a file in the HD (NTFS file system) of my PC...
2
920
by: Arpan | last post by:
Does the file system being used by the O.S. (i.e. FAT32 or NTFS) play a major role as far as executing ASP.NET applications are concerned? Or in other words, does the NTFS file system enhance the...
9
2031
by: Arsen V. | last post by:
Hello, What is the suggested way to store uploaded files? 1) IMAGE type data in an SQL Database table 2) As a file in the NTFS file system Thanks, Arsen
4
3082
by: Joey | last post by:
Hey, How can I add/edit/delete Folder NTFS permissions in .NET? I have a Win2K Box, and WMI is not installed on my servers Thanks ahead! -- Joey
0
400
by: HitSkiper | last post by:
I am getting the error "The security ID structure is invalid." When running this code. Sub SetPermissions(ByRef vPath As String, ByVal UserName As String) Dim objADsSec As ADsSecurity Dim...
2
2360
by: Gerhard | last post by:
I have a .net application that I want to run in a DMZ, with the SQL Server and file system behind another firewall. Is there a secure way to get to files from my application, or would it be better...
4
2029
by: dodulo | last post by:
Hello, I am opening an MDB database in code, (from an MS Access application,) which resides in a secure location to which the current user (of the application) will not have access file system...
2
2390
Jezternz
by: Jezternz | last post by:
Ok, basicly I have a php script that calls apon files using readfile(), which works as it should, however I want to create a folder (in public_html) where ONLY readfile() can get the files, but the...
0
7213
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
7098
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...
0
7298
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7366
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7471
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
5610
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
4698
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
3187
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...
0
1526
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.