Why does ShGetFolderPath return nil when a folder exists on some Vista computers

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;
// 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 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), - .

?

+3
1

, : 1. delphi (unicode ansi) 2. ? , shGetFolderPat? call ( S_OK, ?)

, , PATH - MAX_PATH. ít ( ), . , . .

+2

Source: https://habr.com/ru/post/1732041/


All Articles