{---------------------------------------- シェルを使ってシステムフォルダパスを取得するユニット 2010/09/17(金) ・ 元のSystemFolderPathUnit.pasから分離しリファクタリングして作成した //----------------------------------------} unit ShellSpecialFolderPathUnit; interface uses SysUtils, Windows, ShlObj, uses_end; type TShellSpecialFolder = ( shsfAdminTools, shsfAltStartUp, shsfAppData, shsfCdBurn_Area, shsfCommon_AdminTools, shsfCommon_AltStartUp, shsfCommon_AppData, shsfCommon_DesktopDirectory, shsfCommon_Documents, shsfCommon_Favorites, shsfCommon_Music, shsfCommon_Pictures, shsfCommon_Programs, shsfCommon_StartMenu, shsfCommon_StartUp, shsfCommon_Templates, shsfCommon_Video, shsfCookies, shsfDesktop, shsfDesktopDirectory, shsfFavorites, shsfFonts, shsfHistory, shsfInternet_Cache, shsfLocal_AppData, shsfMyMusic, shsfMyPictures, shsfMyVideo, shsfNetHood, shsfPersonal, shsfPrintHood, shsfProfile, shsfProgram_Files, shsfProgram_Files_Common, shsfProgram_Filesx86, shsfPrograms, shsfRecent, shsfResources, shsfSendTo, shsfStartMenu, shsfStartUp, shsfSystem, shsfSystemx86, shsfTemplates, shsfWindows ); function ShellGetSpecialFolderKeyName(Value: TShellSpecialFolder): String; function ShellGetSpecialFolderPath(Value: TShellSpecialFolder): String; implementation {--------------------------------------- システムフォルダのパスを返す関数 機能: シェルに問い合わせて取得する 有効な文字列はソースの通り(WinXP環境) 備考: uses ShlObjが必要 IE4をShell統合でインストールした Win95,NT4かWin98,2000以降が必要 参考: ・ http://homepage1.nifty.com/ht_deko/junkbox.html#SHSFP ・ ShlObj.pasの中身 履歴: 2005/10/26 ・ 作成 }//(*----------------------------------- function ShellGetSystemFolderPath(Value: Integer): String; var lpszPath: array[0..MAX_PATH] of Char; begin ShlObj.SHGetSpecialFolderPath(HANDLE_FLAG_INHERIT, lpszPath, Value, False); Result := lpszPath; end; function ShellGetSpecialFolderKeyIndex(Value: TShellSpecialFolder): Integer; begin case Value of shsfAdminTools: Result := CSIDL_ADMINTOOLS; shsfAltStartUp: Result := CSIDL_ALTSTARTUP; shsfAppData: Result := CSIDL_APPDATA; shsfCdBurn_Area: Result := CSIDL_CDBURN_AREA; shsfCommon_AdminTools: Result := CSIDL_COMMON_ADMINTOOLS; shsfCommon_AltStartUp: Result := CSIDL_COMMON_ALTSTARTUP; shsfCommon_AppData: Result := CSIDL_COMMON_APPDATA; shsfCommon_DesktopDirectory: Result := CSIDL_COMMON_DESKTOPDIRECTORY; shsfCommon_Documents: Result := CSIDL_COMMON_DOCUMENTS; shsfCommon_Favorites: Result := CSIDL_COMMON_FAVORITES; shsfCommon_Music: Result := CSIDL_COMMON_MUSIC; shsfCommon_Pictures: Result := CSIDL_COMMON_PICTURES; shsfCommon_Programs: Result := CSIDL_COMMON_PROGRAMS; shsfCommon_StartMenu: Result := CSIDL_COMMON_STARTMENU; shsfCommon_StartUp: Result := CSIDL_COMMON_STARTUP; shsfCommon_Templates: Result := CSIDL_COMMON_TEMPLATES; shsfCommon_Video: Result := CSIDL_COMMON_VIDEO; shsfCookies: Result := CSIDL_COOKIES; shsfDesktop: Result := CSIDL_DESKTOP; shsfDesktopDirectory: Result := CSIDL_DESKTOPDIRECTORY; shsfFavorites: Result := CSIDL_FAVORITES; shsfFonts: Result := CSIDL_FONTS; shsfHistory: Result := CSIDL_HISTORY; shsfInternet_Cache: Result := CSIDL_INTERNET_CACHE; shsfLocal_AppData: Result := CSIDL_LOCAL_APPDATA; shsfMyMusic: Result := CSIDL_MYMUSIC; shsfMyPictures: Result := CSIDL_MYPICTURES; shsfMyVideo: Result := CSIDL_MYVIDEO; shsfNetHood: Result := CSIDL_NETHOOD; shsfPersonal: Result := CSIDL_PERSONAL; shsfPrintHood: Result := CSIDL_PRINTHOOD; shsfProfile: Result := CSIDL_PROFILE; shsfProgram_Files: Result := CSIDL_PROGRAM_FILES; shsfProgram_Files_Common: Result := CSIDL_PROGRAM_FILES_COMMON; shsfProgram_Filesx86: Result := CSIDL_PROGRAM_FILESX86; shsfPrograms: Result := CSIDL_PROGRAMS; shsfRecent: Result := CSIDL_RECENT; shsfResources: Result := CSIDL_RESOURCES; shsfSendTo: Result := CSIDL_SENDTO; shsfStartMenu: Result := CSIDL_STARTMENU; shsfStartUp: Result := CSIDL_STARTUP; shsfSystem: Result := CSIDL_SYSTEM; shsfSystemx86: Result := CSIDL_SYSTEMX86; shsfTemplates: Result := CSIDL_TEMPLATES; shsfWindows: Result := CSIDL_WINDOWS; else Assert(False, Format('%s:存在しない型です', ['SHGetSpecialFolderKeyIndex'])); Result := -1; end; end; function ShellGetSpecialFolderKeyName(Value: TShellSpecialFolder): String; begin case Value of shsfAdminTools: Result := 'CSIDL_ADMINTOOLS'; shsfAltStartUp: Result := 'CSIDL_ALTSTARTUP'; shsfAppData: Result := 'CSIDL_APPDATA'; shsfCdBurn_Area: Result := 'CSIDL_CDBURN_AREA'; shsfCommon_AdminTools: Result := 'CSIDL_COMMON_ADMINTOOLS'; shsfCommon_AltStartUp: Result := 'CSIDL_COMMON_ALTSTARTUP'; shsfCommon_AppData: Result := 'CSIDL_COMMON_APPDATA'; shsfCommon_DesktopDirectory: Result := 'CSIDL_COMMON_DESKTOPDIRECTORY'; shsfCommon_Documents: Result := 'CSIDL_COMMON_DOCUMENTS'; shsfCommon_Favorites: Result := 'CSIDL_COMMON_FAVORITES'; shsfCommon_Music: Result := 'CSIDL_COMMON_MUSIC'; shsfCommon_Pictures: Result := 'CSIDL_COMMON_PICTURES'; shsfCommon_Programs: Result := 'CSIDL_COMMON_PROGRAMS'; shsfCommon_StartMenu: Result := 'CSIDL_COMMON_STARTMENU'; shsfCommon_StartUp: Result := 'CSIDL_COMMON_STARTUP'; shsfCommon_Templates: Result := 'CSIDL_COMMON_TEMPLATES'; shsfCommon_Video: Result := 'CSIDL_COMMON_VIDEO'; shsfCookies: Result := 'CSIDL_COOKIES'; shsfDesktop: Result := 'CSIDL_DESKTOP'; shsfDesktopDirectory: Result := 'CSIDL_DESKTOPDIRECTORY'; shsfFavorites: Result := 'CSIDL_FAVORITES'; shsfFonts: Result := 'CSIDL_FONTS'; shsfHistory: Result := 'CSIDL_HISTORY'; shsfInternet_Cache: Result := 'CSIDL_INTERNET_CACHE'; shsfLocal_AppData: Result := 'CSIDL_LOCAL_APPDATA'; shsfMyMusic: Result := 'CSIDL_MYMUSIC'; shsfMyPictures: Result := 'CSIDL_MYPICTURES'; shsfMyVideo: Result := 'CSIDL_MYVIDEO'; shsfNetHood: Result := 'CSIDL_NETHOOD'; shsfPersonal: Result := 'CSIDL_PERSONAL'; shsfPrintHood: Result := 'CSIDL_PRINTHOOD'; shsfProfile: Result := 'CSIDL_PROFILE'; shsfProgram_Files: Result := 'CSIDL_PROGRAM_FILES'; shsfProgram_Files_Common: Result := 'CSIDL_PROGRAM_FILES_COMMON'; shsfProgram_Filesx86: Result := 'CSIDL_PROGRAM_FILESX86'; shsfPrograms: Result := 'CSIDL_PROGRAMS'; shsfRecent: Result := 'CSIDL_RECENT'; shsfResources: Result := 'CSIDL_RESOURCES'; shsfSendTo: Result := 'CSIDL_SENDTO'; shsfStartMenu: Result := 'CSIDL_STARTMENU'; shsfStartUp: Result := 'CSIDL_STARTUP'; shsfSystem: Result := 'CSIDL_SYSTEM'; shsfSystemx86: Result := 'CSIDL_SYSTEMX86'; shsfTemplates: Result := 'CSIDL_TEMPLATES'; shsfWindows: Result := 'CSIDL_WINDOWS'; else Assert(False, Format('%s:存在しない型です', ['SHGetSpecialFolderKeyIndex'])); Result := ''; end; end; function ShellGetSpecialFolderPath(Value: TShellSpecialFolder): String; begin Result := ShellGetSystemFolderPath(ShellGetSpecialFolderKeyIndex(Value)); end; //------------------------------------*) end.