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;