Reputation: 2542
This works on Win7/8, but not on XP, why ?
// uses shlobj;
function GetSpecialFolderPath(Folder: Integer; CanCreate: Boolean): string;
// Gets path of special system folders
//
// Call this routine as follows:
// GetSpecialFolderPath (CSIDL_PERSONAL, false)
// returns folder as result
//
var
FilePath: array [0..255] of char;
begin
SHGetSpecialFolderPath(0, @FilePath[0], FOLDER, CanCreate);
Result := FilePath;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
memo1.Lines.Add('path:|'+GetSpecialFolderPath(CSIDL_ALTSTARTUP, false)+'|')
end;
Thanks
Upvotes: 1
Views: 1323
Reputation: 1627
I try to avoid coding such common needs.
I use this function from JCL : JclSysInfo.GetPersonalFolder;
Upvotes: 1
Reputation: 116180
0..255 is too small. Use the MAX_PATH
constant.
In Vista this folder doesn't exist anymore. I don't know what it returns (a value for backwards compatibility), but apparently it's shorter that 255 characters in Vista.
Upvotes: 1