Entwickler-Ecke

Windows API - Pfad für Desktop


schitho - Fr 10.10.03 00:25
Titel: Pfad für Desktop
Hi,

Windows legt alle Dateien, die sich am Desktop befinden in einem eigenen Ordner ab.

Das Ermitteln des Pfades für den Desktop funktioniert tadellos.

Unter W2000 (XP?) werden aber scheinbar mehrere Pfade verwendet. Nämlich einen für Alle-User und einen für den aktuellen User.

Zum ermitteln des Pfades für den Desktop verwende ich folgenden Code:


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:
function GetSpecialFolder(hWindow: HWND; Folder: Integer): String;
// Systempfade ermitteln
var
  pMalloc: IMalloc;
  pidl: PItemIDList;
  Path: PChar;
begin
  // get IMalloc interface pointer
  if (SHGetMalloc(pMalloc) <> S_OK) then begin
    MessageBox(hWindow, 'Couldn''t get pointer to IMalloc interface.',
               'SHGetMalloc(pMalloc)'16);
    Exit;
  end;

  // retrieve path
  SHGetSpecialFolderLocation(hWindow, Folder, pidl);
  GetMem(Path, MAX_PATH);
  SHGetPathFromIDList(pidl, Path);
  Result := Path;
  FreeMem(Path);

  // free memory allocated by SHGetSpecialFolderLocation
  pMalloc.Free(pidl);
end;


Aufgerufen wird es so:


Delphi-Quelltext
1:
dirPfad:=GetSpecialFolder(Handle, CSIDL_DESKTOPDIRECTORY);                    


Unter W98 funktioniert das auch.

Unter W2000 aber nicht, weil eben nur der Pfad für den aktuellen User ermittelt wird. Zur vollständigen Anzeige benötige ich aber auch den Pfad für den Desktop aller User. Wie komme ich zu diesem??

Gruß
Thomas


Delete - Fr 10.10.03 01:03

Bestimmt nicht im Offtopic. :roll:


Tino - Fr 10.10.03 11:11
Titel: Re: Pfad für Desktop
Hallo!

Dann benutze doch die Konstante CSIDL_COMMON_DESKTOPDIRECTORY.
MDSN hat folgendes geschrieben:
CSIDL_COMMON_DESKTOPDIRECTORY (0x0019)
The file system directory that contains files and folders that appear on the desktop for all users. A typical path is C:\Documents and Settings\All Users\Desktop. Valid only for Windows NT systems.

Gruß
Tino