# Include <windows. h> # include <stdlib. h> void go (hwnd) {char * Ping = "ipconfig/all"; // command char pbuf [1024]; // cache DWORD Len; startupinfo Si; process_information PI; handle hread1, hwrite1; // pipeline read/write handle bool B; security_attributes saattr; saattr. nlength = sizeof (security_attributes); saattr. binherithandle = true; // The Pipe handle is an inherited saattr. lpsecuritydescriptor = NULL; // create an anonymous pipeline. The pipeline handle is B = createpipe (& hread1, & HW Rite1, & saattr, 1024); If (! B) {MessageBox (hwnd, "pipeline creation failed. "," Information ", 0); return;} memset (& Si, 0, sizeof (SI); SI. CB = sizeof (SI); SI. dwflags = startf_usestdhandles | startf_useshowwindow; SI. wshowwindow = sw_hide; SI. hstdoutput = hwrite1; // set the pipeline write handle to be passed to the sub-process. // create the sub-process and run the ping command. The sub-process can inherit if (! CreateProcess (null, ping, null, null, true, 0, null, null, & Si, & PI) {ITOA (getlasterror (), pbuf, 10 ); messageBox (hwnd, pbuf, "information", 0); closehandle (hread1); closehandle (hwrite1); return;} // If the write handle is inherited, it can be disabled locally, otherwise, closehandle (hwrite1) will be blocked when you read the MPs queue; // read the MPs queue content and use the message box to display Len = 1000; dword l; while (readfile (hread1, pbuf, Len, & L, null) {If (L = 0) break; pbuf [l] = '\ 0'; MessageBox (hwnd, pbuf, "information", 0 ); len = 1000;} MessageBox (hwnd, "readfile exit", "information", 0); closehandle (hread1); return;} int main (INT argc, char * argv []) {go (null); Return 0 ;}
Article Reprinted from: http://blog.csdn.net/lpc_china/article/details/5847260