2
2
Imports System.IO
3
3
Imports System.Security.AccessControl
4
4
5
-
6
-
7
5
Module FileExample
8
6
9
7
Sub Main()
@@ -13,13 +11,13 @@ Module FileExample
13
11
Console.WriteLine( "Adding access control entry for " & fileName)
14
12
15
13
' Add the access control entry to the file.
16
- AddFileSecurity(fileName, "DomainName\AccountName" , _
14
+ AddFileSecurity(fileName, "DomainName\AccountName" ,
17
15
FileSystemRights.ReadData, AccessControlType.Allow)
18
16
19
17
Console.WriteLine( "Removing access control entry from " & fileName)
20
18
21
19
' Remove the access control entry from the file.
22
- RemoveFileSecurity(fileName, "DomainName\AccountName" , _
20
+ RemoveFileSecurity(fileName, "DomainName\AccountName" ,
23
21
FileSystemRights.ReadData, AccessControlType.Allow)
24
22
25
23
Console.WriteLine( "Done." )
@@ -29,42 +27,37 @@ Module FileExample
29
27
30
28
End Sub
31
29
32
-
33
30
' Adds an ACL entry on the specified file for the specified account.
34
- Sub AddFileSecurity( ByVal fileName As String , ByVal account As String , _
31
+ Sub AddFileSecurity( ByVal fileName As String , ByVal account As String ,
35
32
ByVal rights As FileSystemRights, ByVal controlType As AccessControlType)
36
-
37
- ' Get a FileSecurity object that represents the
38
- ' current security settings.
39
- Dim fSecurity As FileSecurity = File.GetAccessControl(fileName)
33
+
34
+ Dim fileInfo As New FileInfo(fileName)
35
+ Dim fSecurity As FileSecurity = fileInfo.GetAccessControl()
40
36
41
37
' Add the FileSystemAccessRule to the security settings.
42
- Dim accessRule As FileSystemAccessRule = _
43
- New FileSystemAccessRule(account, rights, controlType)
38
+ Dim accessRule As New FileSystemAccessRule(account, rights, controlType)
44
39
45
40
fSecurity.AddAccessRule(accessRule)
46
41
47
42
' Set the new access settings.
48
- File .SetAccessControl(fileName, fSecurity)
43
+ fileInfo .SetAccessControl(fSecurity)
49
44
50
45
End Sub
51
46
52
-
53
47
' Removes an ACL entry on the specified file for the specified account.
54
- Sub RemoveFileSecurity( ByVal fileName As String , ByVal account As String , _
48
+ Sub RemoveFileSecurity( ByVal fileName As String , ByVal account As String ,
55
49
ByVal rights As FileSystemRights, ByVal controlType As AccessControlType)
56
50
57
- ' Get a FileSecurity object that represents the
58
- ' current security settings.
59
- Dim fSecurity As FileSecurity = File.GetAccessControl(fileName)
51
+ Dim fileInfo As New FileInfo(fileName)
52
+ Dim fSecurity As FileSecurity = fileInfo.GetAccessControl()
60
53
61
54
' Remove the FileSystemAccessRule from the security settings.
62
- fSecurity.RemoveAccessRule( New FileSystemAccessRule(account, _
55
+ fSecurity.RemoveAccessRule( New FileSystemAccessRule(account,
63
56
rights, controlType))
64
57
65
58
' Set the new access settings.
66
- File .SetAccessControl(fileName, fSecurity)
59
+ fileInfo .SetAccessControl(fSecurity)
67
60
68
61
End Sub
69
62
End Module
70
- '</SNIPPET1>
63
+ '</SNIPPET1>
0 commit comments