473,396 Members | 1,864 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,396 software developers and data experts.

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 4611

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

Similar topics

7
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
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
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
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
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
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
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
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
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
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
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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
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
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...

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.