Title: Create a programgroup in the start-menu
Question: How can i create a programgroup in the start-menu ?
Answer:
It's a combination of SHGetSpecialFolderLocation and SHGetPathFromIDList. The
creation itself is done by CreateDirectory.
uses shlobj;
...
function CreateFolder(Foldername: string; aLocation: integer): boolean;
var pIdl: PItemIDList;
hPath: PChar;
begin
Result := False;
if SUCCEEDED(SHGetSpecialFolderLocation(0, aLocation, pidl)) then
begin
hPath := StrAlloc(max_path);
SHGetPathFromIDList(pIdl, hPath);
SetLastError(0);
CreateDirectory(PChar(hPath + '\\' + Foldername), nil );
if (GetLastError()=0) or (GetLastError()=ERROR_ALREADY_EXISTS) then
Result := true;
StrDispose(hPath);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
//constants like 'CSIDL_PROGRAMS' are defined in ShlObj
CreateFolder('MyProgramgroup', CSIDL_PROGRAMS);
end;