unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;
type TForm1 = class(TForm) Memo1: TMemo; Edit1: TEdit; procedure Edit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); private { Private declarations } public { Public declarations } end;
var Form1: TForm1;
implementation
{$R *.dfm} function GetDosOutput(CommandLine: string; Work: string = 'C:\'): string; { Run a DOS program and retrieve its output dynamically while it is running. } var SecAtrrs: TSecurityAttributes; StartupInfo: TStartupInfo; ProcessInfo: TProcessInformation; StdOutPipeRead, StdOutPipeWrite: THandle; WasOK: Boolean; pCommandLine: array[0..255] of AnsiChar; BytesRead: Cardinal; WorkDir: string; Handle: Boolean; begin Result := ''; with SecAtrrs do begin nLength := SizeOf(SecAtrrs); bInheritHandle := True; lpSecurityDescriptor := nil; end; CreatePipe(StdOutPipeRead, StdOutPipeWrite, @SecAtrrs, 0); try with StartupInfo do begin FillChar(StartupInfo, SizeOf(StartupInfo), 0); cb := SizeOf(StartupInfo); dwFlags := STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES; wShowWindow := SW_HIDE; hStdInput := GetStdHandle(STD_INPUT_HANDLE); // don't redirect stdin hStdOutput := StdOutPipeWrite; hStdError := StdOutPipeWrite; end; WorkDir := Work; Handle := CreateProcess(nil, PChar('cmd.exe /C ' + CommandLine), nil, nil, True, 0, nil, PChar(WorkDir), StartupInfo, ProcessInfo); CloseHandle(StdOutPipeWrite); if Handle then try repeat WasOK := windows.ReadFile(StdOutPipeRead, pCommandLine, 255, BytesRead, nil); if BytesRead > 0 then begin pCommandLine[BytesRead] := #0; Result := Result + pCommandLine; end; until not WasOK or (BytesRead = 0); WaitForSingleObject(ProcessInfo.hProcess, INFINITE); finally CloseHandle(ProcessInfo.hThread); CloseHandle(ProcessInfo.hProcess); end; finally CloseHandle(StdOutPipeRead); end; end;
procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if Key = VK_RETURN then begin memo1.text := GetDosOutput(edit1.text); end; end;
end.
>> 1. °³¹ß/½ÇÇà Ç÷§Æû >> (1) OS : >> (2) °³¹ßÅø : >> (3) »ç¿ë Database : >> >> 2. °³¹ß ÁßÀÎ ÇÁ·Î±×·¥ >> >> 3. Áú¹® ³»¿ë >> >> ShellExecute ¸¦ ÀÌ¿ëÇÏ¿© CMD âÀ» ¿©´Â °ÍÀº ÀÍÈ÷ ¾Ë°í ÀÖ½À´Ï´Ù. >> ÇÏÁö¸¸ ±× ¿¸° CMDâ¿¡¼ ¾î¶°ÇÑ µµ½º ¸í·É (¿¹¸¦ µé¾î dir/w ¶ó´øÁö..)À» >> ½ÇÇà½ÃÄÑ ±× Ãâ·ÂµÇ´Â °ªÀ» µ¨ÆÄÀÌÀÇ ¸Þ¸ðÀå¿¡ ¿Å°Ü¿Í Ãâ·ÂÇÏ°í ½Í½À´Ï´Ù¸¸ >> ÀÌ°Ô °ú¿¬ °¡´ÉÇÑÁö ±Ã±ÝÇÕ´Ï´Ù. >> ÇöÀç Á¦°¡ ¾Ë°í ÀÖ´Â Áö½ÄÀ¸·Î´Â >> C:\Windows\dir/w >> filelist.txt >> ÀÌ·±½ÄÀ¸·Î ÆÄÀÏ·Î ÀúÀåÇÏ¿© ±× ÆÄÀÏÀ» ºÒ·¯¿À´Â ¹æ¹ý¹Û¿£ »ý°¢ÀÌ ¾È³ª³×¿ä. >> ¹°·Ð ´Ü¼øÈ÷ ÆÄÀϸ®½ºÆ® ¾ò¾î¿À´Â dir/w °°Àº ¸í·ÉÀÌ¾ß ÆÄÀÏ·Î ÀúÀåÇÏ¿© ±× ÆÄÀÏÀ» >> ¸Þ¸ðÀå¿¡¼ Àоî¿Ã¼öµµ ÀÖÁö¸¸ >> netstat µîÀ» ÀÌ¿ëÇÏ¿© ÁÖ±âÀûÀÎ ½Ã°£À» ¼³Á¤ÇÏ¿© °è¼Ó ¹èÃâµÇ´Â °ªÀ» Àоî¿Í¾ßÇÏ´Â °æ¿ì¿¡´Â >> ´Ù¸¥ ¹æ¹ýÀ» »ç¿ëÇØ¾ß ÇÒ °Í °°¾Æ¿ä. >> >> Á¤¸®ÇÏÀÚ¸é >> ²À CMD âÀ» ¿Áö ¾Ê°í >> µµ½º ¸í·É¾î¸¦ ½ÇÇàÇÏ¿© ±× °á°ú°ªÀ» ¸Þ¸ðÀå¿¡ »Ñ¸®°í ½Í½À´Ï´Ù. >> >>
|