http://download.csdn.net/source/1668710

解决方案 »

  1.   

    http://www.codeproject.com/KB/IP/netcfg.aspx
      

  2.   

    用匿名管道
    google 搜 VC 匿名管道 
      

  3.   

    BOOL CRarFilesList::RarCreateFileList(CString strXpathFileName,CString &strListFileName,bool isAtePath)
    {
    if(isAtePath)
    {
    strXpathFileName=GetAtePath(true)+strXpathFileName;
    }else
    {
    strXpathFileName=GetAppPath()+strXpathFileName;
    }
    CString strCommandLine;
    strCommandLine+="cmd.exe /c "+GetAppPath()+"ftpFileTemp\\Rar.exe vt "+strXpathFileName;

    strListFileName=strXpathFileName.Left(strXpathFileName.GetLength()-4);
    strListFileName+=".lst";

    strCommandLine=strCommandLine+">"+strListFileName;

    SECURITY_ATTRIBUTES sa;
    HANDLE hRead,hWrite;

    sa.nLength = sizeof(SECURITY_ATTRIBUTES);
    sa.lpSecurityDescriptor = NULL;
    sa.bInheritHandle = TRUE;
    if (!CreatePipe(&hRead,&hWrite,&sa,0)) {
    TRACE("Error On CreatePipe()");
    return FALSE;
    }
    STARTUPINFO si;
    PROCESS_INFORMATION pi;
    si.cb = sizeof(STARTUPINFO);
    GetStartupInfo(&si);
    si.hStdError = hWrite;
    si.hStdOutput = hWrite;
    si.wShowWindow = SW_HIDE;
    si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;

    int ifd=0,iFold=0;
    while(ifd!=-1)
    {
    ifd=strListFileName.Find('\\',iFold+1);
    if(ifd!=-1)
    {
    iFold=ifd;
    }

    }
    strListFileName=strListFileName.Right(strListFileName.GetLength()-iFold-1); // if (!CreateProcess(NULL,"cmd.exe /c ping www.huawei.com -t",NULL,NULL,TRUE,NULL,NULL,NULL,&si,&pi)) 
    if (!CreateProcess(NULL,strCommandLine.GetBuffer(strCommandLine.GetLength()),NULL,NULL,TRUE,NULL,NULL,NULL,&si,&pi)) 
    {
    // TRACE("Error on CreateProcess()");
    return FALSE;
    }
    CloseHandle(hWrite);

    char buffer[4096] = {0};
    DWORD bytesRead;
    while (true) 
    {
    if (ReadFile(hRead,buffer,4095,&bytesRead,NULL) == NULL)
    break;
    TRACE("%s\n",CString(buffer)) ;
    Sleep(1000);
    }
    return true;
    }