![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
cmd.exe
chernoruk © (2002-11-15 20:02:00)Скажите, как из своего приложения взаимодействовать с коммандной строкой? да так, чтоб всё это не было видно извне -т.е. что не появлялось черное окно
Eugen Honeker (2002-11-15 20:20:00) [21]повесь на форму
1. memo
2. edit
3. button
и задай в edit комманду
//Featured by NiCoDe - all credits go to him!!!
function CreatePipedProcess(lpCommandLine: PChar): string;
var
lpPipeAttributes: TSecurityAttributes;
hReadPipe: THandle;
hWritePipe: THandle;
lpStartupInfo: TStartupInfo;
lpProcessInformation: TProcessInformation;
lpNumberOfBytesRead: DWORD;
Buffer: array [0..1023] of Char;
begin
Result := "";
ZeroMemory(@lpPipeAttributes, SizeOf(TSecurityAttributes));
lpPipeAttributes.nLength := SizeOf(TSecurityAttributes);
lpPipeAttributes.bInheritHandle := True;
if CreatePipe(hReadPipe, hWritePipe, @lpPipeAttributes, 0) then
begin
ZeroMemory(@lpStartupInfo, SizeOf(TStartupInfo));
lpStartupInfo.cb := SizeOf(TStartupInfo);
lpStartupInfo.dwFlags := STARTF_USESTDHANDLES;
lpStartupInfo.hStdOutput := hWritePipe;
lpStartupInfo.hStdError := hWritePipe;
lpStartupInfo.dwFlags := lpStartupInfo.dwFlags or STARTF_USESHOWWINDOW;
lpStartupInfo.wShowWindow := SW_HIDE;//SW_MINIMIZE;
if CreateProcess(nil, lpCommandLine, nil, nil, True, CREATE_NEW_CONSOLE,
nil, nil, lpStartupInfo, lpProcessInformation) then
try
CloseHandle(hWritePipe);
Buffer[0] := #0;
repeat
Result := Result + Buffer;
ZeroMemory(@Buffer, SizeOf(Buffer));
lpNumberOfBytesRead := 0;
until not ReadFile(hReadPipe, Buffer, SizeOf(Buffer) - 1, lpNumberOfBytesRead, nil);
finally
CloseHandle(hReadPipe);
CloseHandle(lpProcessInformation.hThread);
CloseHandle(lpProcessInformation.hProcess);
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
lpCommandLine: array [0..2 * MAX_PATH] of Char;
begin
ZeroMemory(@lpCommandLine, SizeOf(lpCommandLine));
if ExpandEnvironmentStrings("%ComSpec% /C ", lpCommandLine,
SizeOf(lpCommandLine) - 1) > 0 then
begin
lstrcat(lpCommandLine, PChar(Edit1.Text));
Memo1.Text := CreatePipedProcess(lpCommandLine);
end else
MessageBox(0, "command interpeter not found!", nil, 0);
end;