<pre class="code">
<span class="key">uses</span>
  shlobj;

<span class="key">function</span> CreateFolder(Foldername: <span class="key">String</span>; aLocation: integer): boolean; 
<span class="key">var</span>
  pIdl: PItemIDList; 
  hPath: PChar;
<span class="key">begin</span> 
  Result := False; 
  <span class="key">if</span> SUCCEEDED(SHGetSpecialFolderLocation(0, aLocation, pidl)) <span class="key">then</span> 
  <span class="key">begin</span> 
    hPath := StrAlloc(max_path); 
    SHGetPathFromIDList(pIdl, hPath); 
    SetLastError(0); 
    CreateDirectory(PChar(hPath + '\\' + Foldername), <span class="key">nil</span>); 
    <span class="key">if</span> (GetLastError()=0) <span class="key">or</span> (GetLastError() = ERROR_ALREADY_EXISTS) <span class="key">then</span>
    <span class="key">begin</span>
      Result := true;
    <span class="key">end</span>;
    StrDispose(hPath); 
  <span class="key">end</span>; 
<span class="key">end</span>; 

<span class="key">procedure</span> TForm1.Button1Click(Sender: TObject); 
<span class="key">begin</span> 
  // constants like 'CSIDL_PROGRAMS' are defined in ShlObj 
  CreateFolder('MyProgramgroup',CSIDL_PROGRAMS); 
<span class="key">end</span>;
</pre>