473,657 Members | 2,624 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Programmaticall y 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 SecurityDescrip tor
Dim objDAcl As AccessControlLi st
Dim objAce As Object
Dim objAce1 As AccessControlEn try
Dim objAce2 As AccessControlEn try
Dim objSId As ADsSID
Dim objSIdHex As Object

UserName = "molnarc"
objADsSec = New ADsSecurity
objSecDes = CType(objADsSec .GetSecurityDes criptor("FILE://" &
vPath), SecurityDescrip tor)
objDAcl = CType(objSecDes .DiscretionaryA cl, AccessControlLi st)

objSId = New ADsSID
objSId.SetAs(AD SSECURITYLib.AD S_SID_FORMAT.AD S_SID_SAM,
CStr(UserName))
objSIdHex = objSId.GetAs(AD SSECURITYLib.AD S_SID_FORMAT.AD S_SID_SDDL)

' Add a new objAce so that the User has Full Control on NTFS Files.
objAce1 = New AccessControlEn try
objAce1.Trustee = CStr(objSIdHex)
objAce1.AccessM ask = ActiveDs.ADS_RI GHTS_ENUM.ADS_R IGHT_GENERIC_AL L
objAce1.AceType = ActiveDs.ADS_AC ETYPE_ENUM.ADS_ ACETYPE_ACCESS_ ALLOWED
objAce1.AceFlag s = ActiveDs.ADS_AC EFLAG_ENUM.ADS_ ACEFLAG_INHERIT _ACE
Or ActiveDs.ADS_AC EFLAG_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 AccessControlEn try
objAce2.Trustee = CStr(objSIdHex)
objAce2.AccessM ask = ActiveDs.ADS_RI GHTS_ENUM.ADS_R IGHT_GENERIC_AL L
objAce2.AceType = ActiveDs.ADS_AC ETYPE_ENUM.ADS_ ACETYPE_ACCESS_ ALLOWED
objAce2.AceFlag s = ActiveDs.ADS_AC EFLAG_ENUM.ADS_ ACEFLAG_INHERIT _ACE
Or 1
objDAcl.AddAce( objAce2)

objSecDes.Discr etionaryAcl = objDAcl
' Set Permissions on the NTFS folder.
objADsSec.SetSe curityDescripto r(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 SecurityDescrip tor
Dim objDAcl As AccessControlLi st
Dim objAce As Object
Dim objAce1 As AccessControlEn try
Dim objAce2 As AccessControlEn try
Dim objSId As ADsSID
Dim objSIdHex As Object

UserName = "molnarc"
objADsSec = New ADsSecurity
objSecDes = CType(objADsSec .GetSecurityDes criptor("FILE://" &
vPath), SecurityDescrip tor)
objADsSec.SetSe curityDescripto r(objSecDes) '<-- Error happens here

end sub

Any clue as what i could be doing wrong?


Jul 21 '05 #1
0 4643

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

Similar topics

7
2550
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 w2k pro machine with anonymous access. Fyg this is non commercial website for neighbour members in a carpool with booking possibility. No file upload is allowed/possible/needed. Login is manged by the ASP script
8
6640
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 and I want to copy it to the floppy disk (FAT16 file system). But I need that the file data in the floppy disk is modified (added 1 respect to the original value). For example: I have-> HD file data: ‘hello’
2
928
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 performance of ASP.NET applications? Thanks, Arpan
9
2040
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
3091
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 objSecDes As SecurityDescriptor Dim objDAcl As AccessControlList Dim objAce As Object Dim objAce1 As AccessControlEntry Dim objAce2 As AccessControlEntry
2
2375
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 to have a reverse proxy server in the DMZ and the webserver behind the second firewall?
4
2042
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 access permissions. How do I impersonate a user, (or provide credentials,) when opening a Jet database via ADO, ADOX, etc.? The Open method of the Connection object only provides for the Access Workgroup username and password. Thank you, Daniel...
2
2401
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 general public/web does not have access too. I realize I could just put the folder outside public_html, and it would work, however assuming I don't want too, are there some sorta permissions or something i can use? Summed up: How can I give...
0
8427
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8330
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8850
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8746
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8626
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6178
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4175
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4334
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.