if I execute application it will be opened, but if I execute dos command like for
example: echo something >> file.ext it will be executed by %ComSpec% from
Env. variable. Now code work but if file do not exist a empty cmd.exe window
is showed. I want to only show messagebox "File not found!". Please helpe me
and show me how to modifity code bellow in Delphi 7 Personal. Thanks in advice.
Code: Select all
function RunAProgram(const TheProgram, ItsParameters, DefaultDirectory: string) : Cardinal;
begin
Result := ShellExecute(Application.Handle, 'open', PChar (TheProgram),
PChar (ItsParameters), PChar(DefaultDirectory), SW_SHOWNORMAL);
end;
procedure RunCommand(Cmd, DefDir : string);
var
X : integer;
CmdLine : string;
CmdBuffer: array[0..MAX_PATH] of Char;
begin
CmdLine := '';
Cmd := TrimLeft(Cmd);
X := Pos(#32, Cmd);
if X > 0 then
begin
CmdLine := Copy(Cmd, X + 1, MaxInt);
Cmd := Copy(Cmd, 1, X - 1);
end;
GetEnvironmentVariable('COMSPEC', CmdBUffer, SizeOf(CmdBuffer));
if RunAProgram(Cmd, CmdLine, DefDir) = ERROR_FILE_NOT_FOUND then
begin
if RunAProgram(CmdBuffer, '/C' + Cmd + #32 + CmdLine, DefDir) = error_File_Not_Found then
begin
MessageBox(Application.Handle, PChar('File not found!'),
PChar(Application.Title), MB_ICONWARNING + MB_OK);
end;
end;
end;