When testing our applications, we found that using ShGetFolderPath to return the AppData path, the function returns zero, even if the folder exists on the test computer. When developing a PC, ShGetFolderPath returns the AppData path without errors.
Vista is running on the development computer and test PC.
function GetShellFolder( ID: Cardinal; Create: Boolean = False ): string;
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 returns successfully, but on the test PC, the CSIDL_LOCAL_APPDATA folder does not return.
Does anyone know why the CSIDL_LOCAL_APPDATA folder does not return to the test computer, even if the folder exists on the hard drive? The test machine returns a history folder with CSIDL_HISTORY, but it does not return a local appdata folder with CSIDL_LOCAL_APPDATA.
CSIDL_LOCAL_APPDATA \user\AppData\Local. CSIDL_HISTORY user\user\AppData\Local\Microsoft\Windows\History.
GetShellFolder (CSIDL_LOCAL_APPDATA, True), - .
?