 |
| AndreaVB Forum : API : Can anyone tell me how to get the permission level of a folder??? |
|
|
|
nikunja_28 Level: Trainee
 Registered: 29-08-2006 Posts: 3
|
Can anyone tell me how to get the permission level of a folder???
Hi All,
can anyone tell me how to get the access level of a folder in a machine or in LAN. say the folder is Personal & the permission level is as follows.
Permission for Nikunja Allow Deny
Full Control
Modify Y
Read & Execute Y
List Folder Contents Y
Read Y
Write Y
How to get this data using the API call. please help.its urgent.
|
|
29-08-2006 at 07:26 AM |
|
|
GeoffS Level: VB Lord

 Registered: 29-09-2004 Posts: 536
|
Re: Can anyone tell me how to get the permission level of a folder???
The following code example uses the GetAccessControl and the SetAccessControl methods to add an access control list (ACL) entry and then remove an ACL entry from a directory. You must supply a valid user or group account. These methods return a DirectorySecurity object that encapsulates the access control rules for the directory.
Imports System
Imports System.IO
Imports System.Security.AccessControl
Module DirectoryExample
Sub Main()
Try
Dim DirectoryName As String = "TestDirectory"
MsgBox("Adding access control entry for " + DirectoryName)
' Add the access control entry to the directory.
AddDirectorySecurity(DirectoryName, "MYDOMAIN\MyAccount", FileSystemRights.ReadData, AccessControlType.Allow)
MsgBox("Removing access control entry from " + DirectoryName)
' Remove the access control entry from the directory.
RemoveDirectorySecurity(DirectoryName, "MYDOMAIN\MyAccount", FileSystemRights.ReadData, AccessControlType.Allow)
MsgBox("Done.")
Catch e As Exception
MsgBox(e)
End Try
End Sub
' Adds an ACL entry on the specified directory for the specified account.
Sub AddDirectorySecurity(ByVal FileName As String, ByVal Account As String, ByVal Rights As FileSystemRights, ByVal ControlType As AccessControlType)
' Create a new DirectoryInfoobject.
Dim dInfo As New DirectoryInfo(FileName)
' Get a DirectorySecurity object that represents the
' current security settings.
Dim dSecurity As DirectorySecurity = dInfo.GetAccessControl()
' Add the FileSystemAccessRule to the security settings.
dSecurity.AddAccessRule(New FileSystemAccessRule(Account, Rights, ControlType))
' Set the new access settings.
dInfo.SetAccessControl(dSecurity)
End Sub
' Removes an ACL entry on the specified directory for the specified account.
Sub RemoveDirectorySecurity(ByVal FileName As String, ByVal Account As String, ByVal Rights As FileSystemRights, ByVal ControlType As AccessControlType)
' Create a new DirectoryInfo object.
Dim dInfo As New DirectoryInfo(FileName)
' Get a DirectorySecurity object that represents the
' current security settings.
Dim dSecurity As DirectorySecurity = dInfo.GetAccessControl()
' Add the FileSystemAccessRule to the security settings.
dSecurity.RemoveAccessRule(New FileSystemAccessRule(Account, Rights, ControlType))
' Set the new access settings.
dInfo.SetAccessControl(dSecurity)
End Sub
End Module
|
This Example is from the MS MSDN .NET Framework Developers Guide -
http://msdn2.microsoft.com/en-us/library/k1s94fta.aspx
always a good place to start looking for help.
____________________________
multi-tasking - the ability to hang more than one app. at the same time.
|
|
30-08-2006 at 10:06 AM |
|
|
| AndreaVB Forum : API : Can anyone tell me how to get the permission level of a folder??? |
|
|
|
 |
 |