File tree Expand file tree Collapse file tree 1 file changed +12
-13
lines changed Expand file tree Collapse file tree 1 file changed +12
-13
lines changed Original file line number Diff line number Diff line change @@ -95,30 +95,29 @@ Public Class Analyser
95
95
Public Function HasDirectoryWritePermission() As Boolean
96
96
97
97
Try
98
- Dim writeAllow = False
99
-
100
98
Dim ACRules = New DirectoryInfo(FolderName).GetAccessControl().GetAccessRules( True , True , GetType (Security.Principal.NTAccount))
101
- If ACRules Is Nothing Then Return False
102
99
103
100
Dim identity = Security.Principal.WindowsIdentity.GetCurrent
104
101
Dim principal = New Security.Principal.WindowsPrincipal(identity)
102
+ Dim writeDenied = False
103
+
105
104
For Each FSRule As FileSystemAccessRule In ACRules
105
+ If (FSRule.FileSystemRights And FileSystemRights.Write) = 0 Then Continue For
106
+ Dim ntAccount As Security.Principal.NTAccount = TryCast (FSRule.IdentityReference, Security.Principal.NTAccount)
106
107
107
- If (FSRule.FileSystemRights And FileSystemRights.Write) <= 0 Then Continue For
108
- Dim ntAccount As Security.Principal.NTAccount = FSRule.IdentityReference
109
- If ntAccount Is Nothing Then Continue For
110
- If Not principal.IsInRole(ntAccount.Value) Then Continue For
111
- If FSRule.AccessControlType = AccessControlType.Deny Then Return False
112
- writeAllow = True
108
+ If ntAccount Is Nothing OrElse Not principal.IsInRole(ntAccount.Value) Then Continue For
113
109
114
- Next
110
+ If FSRule.AccessControlType = AccessControlType.Deny Then
111
+ writeDenied = True
112
+ Exit For
113
+ End If
115
114
116
- Return writeAllow
115
+ Next
117
116
117
+ Return Not writeDenied
118
118
Catch ex As System.UnauthorizedAccessException
119
-
119
+ ' Consider logging the exception or notifying the caller
120
120
Return False
121
-
122
121
End Try
123
122
124
123
End Function
You can’t perform that action at this time.
0 commit comments