2009/04/27
システム特殊フォルダの取得プロシージャ
| システム特殊フォルダの取得プロシージャの作成 |
#Region "システム特殊フォルダの取得プロシージャ" ''' <summary> ''' システム特殊フォルダの取得プロシージャ ''' </summary> ''' <param name="intSelectNo">取得したいパスの処理番号(1~20) </param> ''' <returns>取得したパス文字列</returns> ''' <remarks></remarks> Public Function fncGetPath(ByVal intSelectNo As Integer) As String Dim strGetPath As String '戻り値変数初期化 strGetPath = String.Empty '各種パスの取得 Select Case intSelectNo Case 1 'アプリケーションのEXEが実行されたフォルダ strGetPath = System.Windows.Forms.Application.StartupPath Case 2 'システムドライブ strGetPath = (System.Environment.GetFolderPath(System.Environment.SpecialFolder.System)) strGetPath = Mid(strGetPath, 1, 2) '結果: C: Case 3 '共有ファイルフォルダ strGetPath = System.Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles) '結果: C:\Program Files\Common Files Case 4 'クッキーフォルダ strGetPath = System.Environment.GetFolderPath(Environment.SpecialFolder.Cookies) '結果: C:\Documents and Settings\UserName\Cookies Case 5 'デスクトップ strGetPath = System.Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) '結果: C:\Documents and Settings\UserName\デスクトップ Case 6 'お気に入り strGetPath = System.Environment.GetFolderPath(Environment.SpecialFolder.Favorites) '結果: C:\Documents and Settings\UserName\Favorites Case 7 '履歴 strGetPath = System.Environment.GetFolderPath(Environment.SpecialFolder.History) '結果: C:\Documents and Settings\UserName\Local Settings\History Case 8 'インターネットキャッシュ strGetPath = System.Environment.GetFolderPath(Environment.SpecialFolder.InternetCache) '結果: C:\Documents and Settings\UserName\Local Settings\Temporary Internet Files Case 9 'マイドキュメント strGetPath = System.Environment.GetFolderPath(Environment.SpecialFolder.Personal) '結果: C:\Documents and Settings\UserName\My Documents Case 10 'プログラムファイル strGetPath = System.Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) '結果: C:\Program Files Case 11 'スタートメニュー strGetPath = System.Environment.GetFolderPath(Environment.SpecialFolder.StartMenu) '結果: C:\Documents and Settings\UserName\スタート メニュー Case 12 'スタートメニューのプログラム strGetPath = System.Environment.GetFolderPath(Environment.SpecialFolder.Programs) '結果: C:\Documents and Settings\UserName\スタート メニュー\プログラム Case 13 'スタートアップ strGetPath = System.Environment.GetFolderPath(Environment.SpecialFolder.Startup) '結果: C:\Documents and Settings\UserName\スタート メニュー\プログラム\スタートアップ Case 14 '最近使用したドキュメント strGetPath = System.Environment.GetFolderPath(Environment.SpecialFolder.Recent) '結果: C:\Documents and Settings\UserName\Recent Case 15 '「送る」フォルダ strGetPath = System.Environment.GetFolderPath(Environment.SpecialFolder.SendTo) '結果: C:\Documents and Settings\UserName\SendTo Case 16 'ウィンドウズシステムフォルダ 'System.Environment.SystemDirectoryでも可 strGetPath = System.Environment.GetFolderPath(Environment.SpecialFolder.System) '結果: C:\WINDOWS\System32 Case 17 'テンプレート strGetPath = System.Environment.GetFolderPath(Environment.SpecialFolder.Templates) '結果: C:\Documents and Settings\UserName\Templates Case 18 'すべてのユーザーのApplication Dataフォルダ strGetPath = System.Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) '結果: C:\Documents and Settings\All Users\Application Data Case 19 '現在のローミングユーザーのApplication Dataフォルダ strGetPath = System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) '結果: C:\Documents and Settings\UserName\Application Data Case 20 '現在の非ローミングユーザーのApplication Dataフォルダ strGetPath = System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) '結果: C:\Documents and Settings\UserName\Local Settings\Application Data End Select Return strGetPath End Function #End Region
| 使い方 |
Public Class Test Public Shared Sub Main() 'ウィンドウズシステムフォルダの表示 MessageBox.Show(fncGetPath(16), "Windowsのシステムフォルダ") End Sub End Class
管理人のパソコンでの結果
![]() |
カテゴリー: 特殊フォルダの取得 — admin 17:22

コメントはまだありません。