The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Slugsnack on July 17, 2009, 11:54:04 PM

Title: piping
Post by: Slugsnack on July 17, 2009, 11:54:04 PM
so i successfully piped the output of ping.exe to my program which displays it in a read-only dialog :

(http://img6.imageshack.us/img6/299/72503316.jpg)

my question is 'cleaning up'. at the moment i simply called TerminateProcess() on the handle returned in the PROCESS_INFORMATION structure from createprocess. but i realised that left a PING.EXE behind. it would seem the best way would be to get a handle to the cmd.exe that i created and send a WM_CLOSE message to it and let it close everything properly. alternatively i could pipe ctrl-c and 'exit' back to the console. unfortunately i don't know how to send key combos, only text

i tried the sendmessage option already but it's not working. i have no clue why either..

invoke EnumWindows, addr EnumFunc, PingProcessInfo.hProcess
invoke CloseHandle, PingProcessInfo.hProcess


EnumFunc proc hwnd:DWORD, lParam:DWORD
LOCAL dwPID:DWORD

invoke GetWindowThreadProcessId, hwnd, addr dwPID
invoke OpenProcess, PROCESS_ALL_ACCESS, TRUE, dwPID

.IF eax == lParam

push eax
invoke SendMessage, hwnd, WM_CLOSE, NULL, NULL
pop eax
invoke CloseHandle, eax
mov eax, FALSE
ret

.ENDIF

invoke CloseHandle, eax
mov eax, TRUE
ret
EnumFunc endp
Title: Re: piping
Post by: Tedd on July 18, 2009, 04:44:28 PM
Good, you saw you the light :wink

So you're calling cmd.exe to call ping.exe? -- I'm guessing that's a leftover from how you were previously trying to do it.
Just call ping.exe directly (no cmd.exe required), then it's 'your' process and you can do what you want with it.
You can call WaitForSingleObject with the process handle (and a small time-out) to check if it's terminated yet; just keep piping until it's finished.
In the case of keep-pinging-until-ctrl+C, it's actually a signal that's generated by the key combination, not the key combination itself. GenerateConsoleCtrlEvent allows you to generate the ctrl+C event.



P.S. you might want to crop your screenshots to remove anything incriminating.
Title: Re: piping
Post by: Slugsnack on July 18, 2009, 05:34:49 PM
oh sh*t stupid dual screen. THAT WAS NOT WHAT IT LOOKED ! we were messing around.. umm i'm not gonna explain even : [ i'm not gay..

okay lemme try your suggestion, brb
Title: Re: piping
Post by: Astro on July 21, 2009, 11:30:04 PM
I can only guess...

ROFL

Best regards,
Astro.