Mr. Smit
Mr. Smit

Reputation: 2542

get WinXP/Vista/7/8 startup folder

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

Answers (3)

Fred
Fred

Reputation: 1627

I try to avoid coding such common needs.

I use this function from JCL : JclSysInfo.GetPersonalFolder;

Upvotes: 1

Mr. Smit
Mr. Smit

Reputation: 2542

change this CSIDL_ALTSTARTUP to this CSIDL_STARTUP

Upvotes: 1

GolezTrol
GolezTrol

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

Related Questions