Thema: Delphi Autostart Pfad ermitteln

Einzelnen Beitrag anzeigen

Andreas L.
(Gast)

n/a Beiträge
 
#6

Re: Autostart Pfad ermitteln

  Alt 29. Aug 2009, 09:42
Oder gleich Luckies Code nehmen und das Rad nicht nochmal neu erfinden:
Delphi-Quellcode:
uses
  ..., Windows, ActiveX, ShlObj;

function GetShellFolder(CSIDL: integer): string;
var
  pidl : PItemIdList;
  FolderPath : string;
  SystemFolder : Integer;
  Malloc : IMalloc;
begin
  Malloc := nil;
  FolderPath := '';
  SHGetMalloc(Malloc);
  if Malloc = nil then
  begin
    Result := FolderPath;
    Exit;
  end;
  try
    SystemFolder := CSIDL;
    if SUCCEEDED(SHGetSpecialFolderLocation(0, SystemFolder, pidl)) then
    begin
      SetLength(FolderPath, max_path);
      if SHGetPathFromIDList(pidl, PChar(FolderPath)) then
      begin
        SetLength(FolderPath, length(PChar(FolderPath)));
      end;
    end;
    Result := FolderPath;
  finally
    Malloc.Free(pidl);
  end;
end;
http://www.michael-puff.de/Artikel/HOMEDIR.shtml

Aufruf:
Delphi-Quellcode:
var
  s: String;
begin
  s := GetShellFolder(CSIDL_STARTUP); //CSIDL_COMMON_STARTUP wäre der Autostart-Ordner für alle Benutzer
  s := IncludeTrailingPathDelimiter(s); //Backslash anhängen falls nicht vorhanden
  ShowMessage(s);
end;
  Mit Zitat antworten Zitat