Entwickler-Ecke

Windows API - User-Verzeichnis


Andidreas - So 04.03.07 12:23
Titel: User-Verzeichnis
Wie kann ich das Homeverzeichnis des angemeldeten Users ermitteln?

Besten Dank im voraus


Christian S. - So 04.03.07 12:30

Du kannst z.B. die Funktion von hier [http://www.michael-puff.de/Developer/Artikel/2003_2005/HOMEDIR.shtml] verwenden:


Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
function GetShellFolder(CSIDL: integer): string;
var
  pidl                   : PItemIdList;
  FolderPath             : string;
  SystemFolder           : Integer;
  Malloc                 : IMalloc;
begin
  Malloc := nil;
  FolderPath := '';
  SHGetMalloc(Malloc);
  if Malloc = nil then
  begin
    Result := FolderPath;
    Exit;
  end;
  try
    SystemFolder := CSIDL;
    if SUCCEEDED(SHGetSpecialFolderLocation(0, SystemFolder, pidl)) then
    begin
      SetLength(FolderPath, max_path);
      if SHGetPathFromIDList(pidl, PChar(FolderPath)) then
      begin
        SetLength(FolderPath, length(PChar(FolderPath)));
      end;
    end;
    Result := FolderPath;
  finally
    Malloc.Free(pidl);
  end;
end;


Die CSIDL_...-Konstanten findest Du hier [http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/enums/csidl.asp].


Andidreas - So 04.03.07 13:06

Danke. Klappt bestens.