uses ShlObj, ActiveX;function GetSystemPath(Folder: Integer): string; var PIDL: PItemIDList; Path: LPSTR; AMalloc: IMalloc; begin Path := StrAlloc(MAX_PATH); SHGetSpecialFolderLocation(Application.Handle, Folder, PIDL); if SHGetPathFromIDList(PIDL, Path) then Result := Path; SHGetMalloc(AMalloc); AMalloc.Free(PIDL); StrDispose(Path); end;
直接用API var key,Sys32Dir: string; pSys32Dir: array[0..Max_Path] of char; begin GetSystemDirectory(pSys32Dir,Max_Path); Sys32Dir := StrPas(pSys32Dir); ShowMessage(Sys32Dir); end;
var
PIDL: PItemIDList;
Path: LPSTR;
AMalloc: IMalloc;
begin
Path := StrAlloc(MAX_PATH);
SHGetSpecialFolderLocation(Application.Handle, Folder, PIDL);
if SHGetPathFromIDList(PIDL, Path) then
Result := Path;
SHGetMalloc(AMalloc);
AMalloc.Free(PIDL);
StrDispose(Path);
end;
var
key,Sys32Dir: string;
pSys32Dir: array[0..Max_Path] of char;
begin
GetSystemDirectory(pSys32Dir,Max_Path);
Sys32Dir := StrPas(pSys32Dir);
ShowMessage(Sys32Dir);
end;