borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (How to Create Demo Version)Next Topic (Problem with Exe) New Topic New Poll Post Reply
AndreaVB Forum : API : Can anyone tell me how to get the permission level of a folder???
Poster Message
nikunja_28
Level: Trainee

Registered: 29-08-2006
Posts: 3

icon 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
View Profile Send Email to User Show All Posts | Quote Reply
GeoffS
Level: VB Lord


Registered: 29-09-2004
Posts: 536
icon Re: Can anyone tell me how to get the permission level of a folder???

Hi,
Security in Windows is handled by ACL's (Access Control Lists) which hold the entries of the permissions that you want to read in an ACE (Access Control Entry) Object. Getting at this is easiest in VB.NET as you can use the System.Security.AccessControl namespace to directly return what you want. Using API's in VB6 is not a method I have actually used myself, but if you take a look at :-
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/secauthz/security/using_authorization_in_visual_basic.asp
it should lead you to all that you need for the task.
Hope that helps a bit.


____________________________
multi-tasking - the ability to hang more than one app. at the same time.

29-08-2006 at 08:42 AM
View Profile Send Email to User Show All Posts | Quote Reply
nikunja_28
Level: Trainee

Registered: 29-08-2006
Posts: 3
icon Re: Can anyone tell me how to get the permission level of a folder???

hi,

thanks for a quick response.can u share the piece of vb.net code which can do the wonder

nikunja.

29-08-2006 at 12:15 PM
View Profile Send Email to User Show All Posts | Quote Reply
GeoffS
Level: VB Lord


Registered: 29-09-2004
Posts: 536
icon 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
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : API : Can anyone tell me how to get the permission level of a folder???
Previous Topic (How to Create Demo Version)Next Topic (Problem with Exe) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder