對dos 撈資料form http://hp.vector.co.jp/authors/VA003525/Jindex.htm
procedure TForm1.Button1Click(Sender: TObject);
var StartupInfo: TStartupInfo;
ProcessInfo: TProcessInformation;
hRead, hWrite: THandle;
Buff: array[0..4095] of Char;
BuffSize, Len: Integer;
begin
CreatePipe(hRead, hWrite, nil, 0);
FillChar(StartupInfo, Sizeof(StartupInfo), 0);
with StartupInfo do begin
cb := Sizeof(StartupInfo);
dwFlags := STARTF_USESTDHANDLES or STARTF_USESHOWWINDOW;
hStdOutput := hWrite;
wShowWindow := SW_HIDE;
end;
if CreateProcess('\Windows\Command\Attrib.exe', nil, nil, nil,
True, 0, nil, nil, StartupInfo, ProcessInfo) then begin
while WaitForSingleObject(ProcessInfo.hProcess, 500) = WAIT_TIMEOUT do
Application.ProcessMessages;
CloseHandle(hWrite);
BuffSize := Sizeof(Buff) - 1;
while True do begin
Len := FileRead(hRead, Buff, BuffSize);
Buff[Len] := #0;
Memo1.Lines.Add(Buff);
if Len < BuffSize then break;
end;
end;
CloseHandle(hRead);
end;
對dos 貼資料
1)
hDosWin := FindWindow('tty', nil);
PostMessage(hDOSWin, WM_COMMAND, 57360, 0);
2)
hDosWin := FindWindow('tty', nil);
SetForegroundWindow(hDosWin);
keybd_event(VK_CANCEL, MapVirtualKey(VK_CANCEL, 0), 0, 0);
keybd_event(VK_CANCEL, MapVirtualKey(VK_CANCEL, 0), KEYEVENTF_KEYUP, 0);
沒有留言:
張貼留言