While testing our apps we found that using ShGetFolderPath to return the AppData path the function returns nil even though the folder exists on a test PC. On the development PC ShGetFolderPath returns the AppData path with no error.
The development PC and the test PC are running Vista.
function GetShellFolder( ID: Cardinal; Create: Boolean = False ): string;
// This function is a superset of SHGetSpecialFolderPath, included with
// earlier versions of the Shell. On systems preceeding those including
// Shell32.dll version 5.0 (Windows Millennium Edition (Windows Me) and
// Windows 2000), SHGetFolderPath was obtained through SHFolder.dll,
// distributed with Microsoft Internet Explorer 4.0 and later versions.
// Takes the CSIDL of a folder and returns the path or 'Could not determine
// folder path' if it does not exist. Creates the folder if it does not
// exist if Create is true.
var
Res: HResult;
Path: array [ 0 .. Max_Path ] of Char;
begin
if Create then
ID := ID or csidl_Flag_Create;
Res := ShGetFolderPath( 0, ID, 0, shgfp_Type_Current, Path );
if S_OK <> Res then
begin
Result := 'Could not determine folder path';
raise Exception.Create( 'Could not determine folder path' );
end;
Result := Path;
end;
GetShellFolder( CSIDL_LOCAL_APPDATA, False );
On the development machine the CSIDL_LOCAL_APPDATA path is returned successfully, but on a test PC the CSIDL_LOCAL_APPDATA folder is not returned.
Does anyone know why the CSIDL_LOCAL_APPDATA folder is not returned on the test PC even though the folder exists on the hard drive? The test machine returns the history folder with CSIDL_HISTORY, yet it does not return the local appdata folder with CSIDL_LOCAL_APPDATA.
On the test PC explorer shows the CSIDL_LOCAL_APPDATA folder as users\user\AppData\Local. On the test PC explorer shows the CSIDL_HISTORY folder as users\user\AppData\Local\Microsoft\Windows\History.
if we call GetShellFolder( CSIDL_LOCAL_APPDATA, True) the function still does not return the folder path.
What am I doing wrong or how can I fix this problem?