-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclsCommonAppFolder.vb
65 lines (54 loc) · 2.79 KB
/
clsCommonAppFolder.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
Imports System
Imports System.IO
Imports System.Security.AccessControl
Imports System.Security.Principal
Public Class clsCommonAppFolder
Private applicationFolder As String
Private companyFolder As String
Private Shared ReadOnly directory As String = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)
Public Sub New(ByVal companyFolder As String, ByVal applicationFolder As String)
Me.New(companyFolder, applicationFolder, False)
End Sub
Public Sub New(ByVal companyFolder As String, ByVal applicationFolder As String, ByVal allUsers As Boolean)
Me.applicationFolder = applicationFolder
Me.companyFolder = companyFolder
CreateFolders(allUsers)
End Sub
Public ReadOnly Property ApplicationFolderPath As String
Get
Return Path.Combine(CompanyFolderPath, applicationFolder)
End Get
End Property
Public ReadOnly Property CompanyFolderPath As String
Get
Return Path.Combine(directory, companyFolder)
End Get
End Property
Private Sub CreateFolders(ByVal allUsers As Boolean)
Dim directoryInfo As DirectoryInfo
Dim directorySecurity As DirectorySecurity
Dim rule As AccessRule
Dim securityIdentifier As SecurityIdentifier = New SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, Nothing)
If Not IO.Directory.Exists(CompanyFolderPath) Then
directoryInfo = IO.Directory.CreateDirectory(CompanyFolderPath)
Dim modified As Boolean
directorySecurity = directoryInfo.GetAccessControl()
rule = New FileSystemAccessRule(securityIdentifier, FileSystemRights.Write Or FileSystemRights.ReadAndExecute Or FileSystemRights.Modify, AccessControlType.Allow)
directorySecurity.ModifyAccessRule(AccessControlModification.Add, rule, modified)
directoryInfo.SetAccessControl(directorySecurity)
End If
If Not IO.Directory.Exists(ApplicationFolderPath) Then
directoryInfo = IO.Directory.CreateDirectory(ApplicationFolderPath)
If allUsers Then
Dim modified As Boolean
directorySecurity = directoryInfo.GetAccessControl()
rule = New FileSystemAccessRule(securityIdentifier, FileSystemRights.Write Or FileSystemRights.ReadAndExecute Or FileSystemRights.Modify, InheritanceFlags.ContainerInherit Or InheritanceFlags.ObjectInherit, PropagationFlags.InheritOnly, AccessControlType.Allow)
directorySecurity.ModifyAccessRule(AccessControlModification.Add, rule, modified)
directoryInfo.SetAccessControl(directorySecurity)
End If
End If
End Sub
Public Overrides Function ToString() As String
Return ApplicationFolderPath
End Function
End Class