tbaseflug
asked on
Programtically Set Folder Security
Is there a way to programtically set permissions at the folder / directory level?
ASKER
TheLearnedOne -
Using the below, from the link - do I have to pass in any data such as the path:
Public Shared Function SetPermissions(ByVal path As String, ByVal user As String, ByVal rights As String) As String
Dim p As System.Diagnostics.Process = New System.Diagnostics.Process
Try
p.StartInfo.FileName = "CACLS"
p.StartInfo.Arguments = path & "/E /P " & user & ":" & rights
p.StartInfo.RedirectStanda rdInput = True
p.StartInfo.RedirectStanda rdOutput = True
p.StartInfo.UseShellExecut e = False
p.StartInfo.WindowStyle = Diagnostics.ProcessWindowS tyle.Hidde n
p.Start()
p.WaitForExit(1000)
Return p.StandardOutput.ReadToEnd .ToString
Catch ex As Exception
Return ex.Message
Finally
If Not p Is Nothing Then
p.Dispose()
p = Nothing
End If
End Try
End Function
Using the below, from the link - do I have to pass in any data such as the path:
Public Shared Function SetPermissions(ByVal path As String, ByVal user As String, ByVal rights As String) As String
Dim p As System.Diagnostics.Process
Try
p.StartInfo.FileName = "CACLS"
p.StartInfo.Arguments = path & "/E /P " & user & ":" & rights
p.StartInfo.RedirectStanda
p.StartInfo.RedirectStanda
p.StartInfo.UseShellExecut
p.StartInfo.WindowStyle = Diagnostics.ProcessWindowS
p.Start()
p.WaitForExit(1000)
Return p.StandardOutput.ReadToEnd
Catch ex As Exception
Return ex.Message
Finally
If Not p Is Nothing Then
p.Dispose()
p = Nothing
End If
End Try
End Function
I modified your comment to show the new function.
Explanation:
/E - Edit ACL instead of replacing it
/P - Replace specified user's access rights: N=None, R=Read, W=Write, C=Change, F=Full
Bob
Explanation:
/E - Edit ACL instead of replacing it
/P - Replace specified user's access rights: N=None, R=Read, W=Write, C=Change, F=Full
Bob
ASKER
Bob -
Thanks! So, the following should work, correct:
SetPermissions("C:\inetpub \wwwroot\C ardellRepo rt", "everyone", "F")
Thanks! So, the following should work, correct:
SetPermissions("C:\inetpub
I would hope so :)
Bob
Bob
I used code from this link to do the same thing, but it's written in c#.
http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=e6098575-dda0-48b8-9abf-e0705af065d9
and this guy managed to convert some of the code to vb.net, awesome!
credits to graye
https://www.experts-exchange.com/questions/21352828/How-to-Read-Set-Folder-Permissons-in-VB-NET.html
http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=e6098575-dda0-48b8-9abf-e0705af065d9
and this guy managed to convert some of the code to vb.net, awesome!
credits to graye
https://www.experts-exchange.com/questions/21352828/How-to-Read-Set-Folder-Permissons-in-VB-NET.html
ASKER
ihenry -
Would this work in a web form?
Would this work in a web form?
It would work to a certain stages. Try to copy and paste the code into another class and use it from your webform and make sure your web app security context has enough privilege to modify NTFS permission of the folder.
What I like most about the code is that it handles the "ACEs ordering" while cacls.exe utility in some cases fails to do so, which can causes some NTFS permission entries to be ineffective. Another problem with cacls.exe utility, it sucks at propagating inheritable ACEs and if you want to have that feature in your code, you might need to consider another utility like xcacls.exe as a replacement (unfortunately, the latter mentioned utility comes with another problems).
What I like most about the code is that it handles the "ACEs ordering" while cacls.exe utility in some cases fails to do so, which can causes some NTFS permission entries to be ineffective. Another problem with cacls.exe utility, it sucks at propagating inheritable ACEs and if you want to have that feature in your code, you might need to consider another utility like xcacls.exe as a replacement (unfortunately, the latter mentioned utility comes with another problems).
ASKER
ihenry -
I will give it a try and let you know.
TheLearnedOne -
I have been trying to set it from the example provided and for some reason it just seems to ignore it - do you know if I have toput the entire path folder in question, or just the folder name itself?
I will give it a try and let you know.
TheLearnedOne -
I have been trying to set it from the example provided and for some reason it just seems to ignore it - do you know if I have toput the entire path folder in question, or just the folder name itself?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
https://www.experts-exchange.com/questions/21276191/Modify-File-Permissions-in-VB-NET.html
Bob