3 Imports System.Windows.Forms
4 Imports Microsoft.Win32
6 Public Class MySpecialPath
8 Public Shared ReadOnly Property UserAppDataPath() As String
10 Return GetFileSystemPath(Environment.SpecialFolder.ApplicationData)
14 Public Shared ReadOnly Property UserAppDataPath(ByVal productName As String) As String
16 Return GetFileSystemPath(Environment.SpecialFolder.ApplicationData, productName)
20 Public Shared ReadOnly Property CommonAppDataPath() As String
22 Return GetFileSystemPath(Environment.SpecialFolder.CommonApplicationData)
26 Public Shared ReadOnly Property LocalUserAppDataPath() As String
28 Return GetFileSystemPath(Environment.SpecialFolder.LocalApplicationData)
32 Public Shared ReadOnly Property CommonAppDataRegistry() As RegistryKey
34 Return GetRegistryPath(Registry.LocalMachine)
38 Public Shared ReadOnly Property UserAppDataRegistry() As RegistryKey
40 Return GetRegistryPath(Registry.CurrentUser)
45 Private Shared Function GetFileSystemPath(ByVal folder As Environment.SpecialFolder) As String
47 Dim path As String = String.Format("{0}{3]{1}{3}{2}", _
48 Environment.GetFolderPath(folder), _
49 Application.CompanyName, _
50 Application.ProductName,
51 System.IO.Path.DirectorySeparatorChar.ToString)
54 SyncLock GetType(Application)
55 If Not Directory.Exists(path) Then
56 Directory.CreateDirectory(path)
60 End Function 'GetFileSystemPath
62 Private Shared Function GetFileSystemPath(ByVal folder As Environment.SpecialFolder, ByVal productName As String) As String
64 Dim path As String = String.Format("{0}{3]{1}{3}{2}", _
65 Environment.GetFolderPath(folder), _
66 Application.CompanyName, _
68 System.IO.Path.DirectorySeparatorChar)
71 SyncLock GetType(Application)
72 If Not Directory.Exists(path) Then
73 Directory.CreateDirectory(path)
77 End Function 'GetFileSystemPath
79 Private Shared Function GetRegistryPath(ByVal key As RegistryKey) As RegistryKey
81 Dim basePath As String
82 If key Is Registry.LocalMachine Then
87 Dim path As String = String.Format("{0}\{1}\{2}", _
89 Application.CompanyName, _
90 Application.ProductName)
91 ' パスのレジストリ・キーの取得(および作成)
92 Return key.CreateSubKey(path)
93 End Function 'GetRegistryPath