Einzelnen Beitrag anzeigen

Benutzerbild von Martin K
Martin K

Registriert seit: 20. Okt 2005
919 Beiträge
 
Turbo Delphi für Win32
 
#30

Re: Programmstart durch Autostart - kann man das herausfinde

  Alt 16. Sep 2006, 15:46
So hab jetzt deinen Code etwas umgebaut und mit den entsprechenden Teilen aus meinem Code ergänzt:
Delphi-Quellcode:
procedure TForm3.buttonclick(Sender: TObject);

function FindExecute(const Command: String): String;

  function GetWinPath(const Path: String): String;
  begin
    Result := StringReplace(StringReplace(StringReplace(StringReplace(Trim(StringReplace(Path, 'file:///', '', [rfIgnoreCase])), '\', PathDelim, [rfReplaceAll]), '/', PathDelim, [rfReplaceAll]), PathDelim+PathDelim, PathDelim, [rfReplaceAll]), '%20', ' ', [rfReplaceAll]);
  end;

  function ExpandEnvironmentPath(const Path: String): String;
  begin
    SetLength(Result, ExpandEnvironmentStrings(PChar(Path), nil, 0));
    ExpandEnvironmentStrings(PChar(Path), PChar(Result), Length(Result));
    Result := PChar(Result);
  end;

var i, j: Integer; Path, PathExt: TStrings;
begin
  Result := ExpandEnvironmentPath(Command);
  Result := GetWinPath(Result);
  if not FileExists(Result) then
  begin
    if DirectoryExists(Result) then
      Result := IncludeTrailingPathDelimiter(Result)
    else
    begin
      Path := TStringList.Create;
      PathExt := TStringList.Create;
      try
        Path.Delimiter := PathSep;
        Path.DelimitedText := GetEnvironmentVariable('Path');
        Path.Append(GetShellFolder($0028));
        PathExt.Delimiter := PathSep;
        PathExt.DelimitedText := LowerCase(GetEnvironmentVariable('PathExt'));
        if PathExt.Count > 0 then
          for i := 0 to Pred(PathExt.Count) do
            if FileExists(ChangeFileExt(Result, PathExt[i])) then
            begin
              Result := ChangeFileExt(Result, PathExt[i]);
              Exit;
            end;
        if Path.Count > 0 then
          for j := 0 to Pred(Path.Count) do
          begin
            if FileExists(IncludeTrailingPathDelimiter(Path[j])+Result) then
            begin
              Result := IncludeTrailingPathDelimiter(Path[j])+Result;
              Exit;
            end
            else
            if DirectoryExists(IncludeTrailingPathDelimiter(Path[j])+Result) then
            begin
              Result := IncludeTrailingPathDelimiter(IncludeTrailingPathDelimiter(Path[j])+Result);
              Exit;
            end
            else
            if PathExt.Count > 0 then
              for i := 0 to Pred(PathExt.Count) do
                if FileExists(ChangeFileExt(IncludeTrailingPathDelimiter(Path[j])+Result, PathExt[i])) then
                begin
                  Result := ChangeFileExt(IncludeTrailingPathDelimiter(Path[j])+Result, PathExt[i]);
                  Exit;
                end;
          end;
        Result := '';
      finally
        Path.Free;
        PathExt.Free;
      end;
    end;
  end;
end;

var s,param: string; i: Integer; b: Boolean;
begin
  if Sender is TButton then
  begin
    s := FindExecute(programs[(Sender as TButton).tag]);
    param := '';
    if s = 'then
    begin
      s := programs[(Sender as TButton).tag];
      i := 1;
      b := False;
      while (i <= Length(s)) and ((s[i] <> ' ') or b) do
      begin
        if s[i] = '"then
          b := not b;
        Inc(i);
      end;
      param := Trim(Copy(s, i+1, Length(s)));
      s := FindExecute(StringReplace(Trim(Copy(s, 1, i-1)), '"', '', [rfReplaceAll]));
    end;
    if s = 'then
      ShowMessage('Fehlerhafter Autostart-Eintrag')
    else
      ShellExecute(Handle, 'open', PChar(s), PChar(param), PChar(GetShellFolder($0028)), 1);
  end;
end;
Mit den Menschen ist es wie mit Computern -
es gibt Nullen und Einsen.
  Mit Zitat antworten Zitat