Redirect ping data to an anonymous Pipeline

Source: Internet
Author: User
# 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.