function TForm1.GetSpecialFolder(hWindow: HWND; Folder: Integer):
String;
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;
SHGetSpecialFolderLocation(hWindow, Folder, pidl);
GetMem(Path, MAX_PATH);
SHGetPathFromIDList(pidl, Path);
Result := Path;
FreeMem(Path);
pMalloc.Free(pidl);
end;
procedure TForm1.findpath;
var Handle: HWND;
begin
CSIDLPROGRAMS:=(GetSpecialFolder(
Handle, CSIDL_PROGRAMS));
CSIDLCOMMONPROGRAMS:=(GetSpecialFolder(
Handle, CSIDL_COMMON_PROGRAMS));
CSIDLDESKTOP:=(GetSpecialFolder(
Handle, CSIDL_Desktopdirectory));
CSIDLCOMMONDESKTOP:=(GetSpecialFolder(
Handle, CSIDL_COMMON_Desktopdirectory));
CSIDLRECENT:=(GetSpecialFolder(
Handle, CSIDL_RECENT));
CSIDLPERSONAL:=(GetSpecialFolder(
Handle, CSIDL_PERSONAL));
CSIDLFAVORITES:=(GetSpecialFolder(
Handle, CSIDL_FAVORITES));
CSIDLCOMMONFAVORITES:=(GetSpecialFolder(
Handle, CSIDL_COMMON_FAVORITES));
CSIDLNETWORK:=(GetSpecialFolder(
Handle, CSIDL_NETHOOD));
CSIDLVORLAGEN:=(GetSpecialFolder(
Handle, CSIDL_TEMPLATES));
end;
// CSIDLPROGRAMS, ... sind globale Variablen vom Typ string
procedure TForm1.Button1Click(Sender: TObject);
var slCmdLine: PAnsiChar;
path:
string;
begin
path:=CSIDLPERSONAL;
slCmdLine := Pchar(path);
ShellExecute(
handle,
nil, '
explorer.exe', slCmdLine, 0, SW_SHOWNORMAL);
end;