473,561 Members | 3,124 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Add and Remove Folder Permissions in VB.Net

Hi

I'm using WMI to set and remove folderpermissio ns and it sems to work
fine, sometimes. I start by having the folderpermisson s manuly set to
Everyone and Everone has full rights. When I'm setting and removing
permissons on a mapped folder in the network it works fine but when
doing the same thing on a folder om my harddrive Everyone does not get
removed.
Does anyone have any idea how to fix this or how to set and remove
folderpermisson s in another way.
Here is the code I'm using:
Try
'Path to folder to change permissions for

Dim mp As New ManagementPath( )

'mp.Server = "servername "

'mp.NamespacePa th = "root\cimv2 "

mp.RelativePath =
"\\MASCHINENAME \root\CIMV2:Win 32_LogicalFileS ecuritySetting. Path=""PATHTOFO LDER"""
'"Win32_Logical FileSecuritySet ting.Path='" +
path.Replace("\ ", "\\") + "'"
Dim objFile As New ManagementObjec t(mp)

Dim options As New InvokeMethodOpt ions(Nothing, New
TimeSpan(0, 0, 0, 5))

Dim outparams As ManagementBaseO bject =
objFile.InvokeM ethod("GetSecur ityDescriptor", Nothing, options)

Dim securityDescrip tor As ManagementBaseO bject =
outparams("Desc riptor")

lblMessage.Text += "Got SD...<br>"

Dim dacl As ManagementBaseO bject() =
securityDescrip tor("DACL")

Dim oldACE As ManagementBaseO bject

Dim trustee As ManagementBaseO bject

lblMessage.Text += "Print old DACL<br>"

For Each oldACE In dacl

trustee = CType(oldACE("T rustee"),
ManagementBaseO bject)

lblMessage.Text += trustee("Name") .ToString() & " " &
oldACE("AccessM ask").ToString( ) & " " & oldACE("AceType ").ToString () &
"<br>"

Next

Dim win32Trustee As New ManagementClass ("Win32_Trustee ")

'Create Trustee for User

Dim newTrusteeUser As ManagementObjec t =
win32Trustee.Cr eateInstance

Dim UserAcct As String = "LDAP string to user in
AD (without LDAP://)"

Dim UserNamePath As String = "LDAP://" & UserAcct

Dim dirEnt As New DirectoryEntry( UserNamePath)

Dim UserName As String =
dirEnt.Properti es("sAMAccountN ame")(0)

Dim UserSid As Byte() = dirEnt.Properti es("objectsid") (0)

dirEnt.Dispose( )

newTrusteeUser( "Name") = UserName

newTrusteeUser( "SID") = UserSid

newTrusteeUser( "SIDLength" ) = UserSid.Length

'Create ACE for User

Dim win32Ace As New ManagementClass ("Win32_ACE" )

Dim newACEUser As ManagementObjec t =
win32Ace.Create Instance

newACEUser("Tru stee") = newTrusteeUser

newACEUser("Ace Flags") = 3

newACEUser("Ace Type") = 0

newACEUser("Acc essMask") = 1179817

'Create Trustee for Domain Admin

Dim newTrusteeAdmin As ManagementObjec t =
win32Trustee.Cr eateInstance

Dim AdminAcct As String ="LDAP string to Domain Admins in
AD (without LDAP://)"

Dim AdminNamePath As String = "LDAP://" & AdminAcct

dirEnt = New DirectoryEntry( AdminNamePath)

Dim AdminName As String =
dirEnt.Properti es("sAMAccountN ame")(0)

Dim adminSid As Byte() = dirEnt.Properti es("objectsid") (0)

dirEnt.Dispose( )

newTrusteeAdmin ("Name") = AdminName

newTrusteeAdmin ("SID") = adminSid

newTrusteeAdmin ("SIDLength" ) = adminSid.Length

'Create ACE for Domain Admins

Dim newACEAdmin As ManagementObjec t =
win32Ace.Create Instance

newACEAdmin("Tr ustee") = newTrusteeAdmin

newACEAdmin("Ac eFlags") = 3

newACEAdmin("Ac eType") = 0

newACEAdmin("Ac cessMask") = 2032127

'set new dacl

Dim newAces() As ManagementBaseO bject = New
ManagementBaseO bject() {newACEUser, newACEAdmin}

securityDescrip tor("DACL") = newAces

'call method, set sd

Dim args1() As Object = {securityDescri ptor}

Dim retval As UInt32 =
objFile.InvokeM ethod("SetSecur ityDescriptor", args1)

lblMessage.Text += "<br>SetSecurit yDescriptor ReturnStatus
= " & System.Convert. ToInt32(retval)
Catch ex As Exception

lblMessage.Text = "Setting permission failed: " &
ex.Message

End Try

End Sub
Nov 20 '05 #1
0 3623

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

Similar topics

0
3497
by: Andrew Crowe | last post by:
Hi guys, We're using the ISAPI version of PHP with IIS5.0 On some websites for some reason any php file in the websites root is given the path winnt/system32 (getcwd() returns "C:\WINNT\system32"), while files in a folder are given the correct dir. To fix this I created a file that's included to all the files from php.ini
7
2546
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...
3
3649
by: roger | last post by:
I've created a web setup project for my aspnet app, and added a web folder item "tmp" to the File System editor under the web application folder. (My app uses this folder for generating image files and such) Problem is, I can't figure out how to make this folder writable by the ASPNET user during installation.I've set the writable property...
1
1455
by: Codex Twin | last post by:
Hello folks Is it possible to add/remove Read Permissions (and any other NTFS permissions) to a folder programmatically via an ASP.NET page? Thanks.
0
1181
by: Johan | last post by:
Hi I'm using WMI to set and remove folderpermissions and it sems to work fine, sometimes. I start by having the folderpermissons manuly set to Everyone and Everone has full rights. When I'm setting and removing permissons on a mapped folder in the network it works fine but when doing the same thing on a folder om my harddrive Everyone does...
6
14838
by: Jeff | last post by:
Hi - I understand how to create a directory folder, but how can I programatically create a _shared_ directory folder and set its permissions?? (I'm using VB.NET.) Thanks for your help. - Jeff
5
13259
by: Mitchell S. Honnert | last post by:
Is there a way, given the full path of a folder on a network, that one can programatically tell if you have Read access to that folder? I have an application where the user is able to select a number of search folders using the standard dialog control. There shouldn't be an issue with the search folder being on a local drive or a network...
2
4110
by: skinnybloke | last post by:
Hi - I have a file permissions problem with PHP. I am using a product called Actinic to develop a shopping cart. This creates a subfolder named ACATALOG into which it loads all of its files. The permissions for this folder is set to 777. I have set up a page in the package to call a .PHP page. When I try to run the PHP page I get the...
6
29457
by: Andy Fish | last post by:
Hi, From what I can gather, under Asp.Net 2.0, it is safe to put data and config files underneath the app_data in the web root and they will not be served directly to the browser from a URL. Can anyone explain just how this feature works. is app_data a reserved name for IIS and ASP.Net, or is there some jiggery pokery going on behind the...
0
7858
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. ...
0
8085
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...
1
7614
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7928
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...
0
6206
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5185
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3615
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...
1
2066
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 we have to send another system
0
892
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.