在用ShellExecute调用某个应用程序(比如ping),想在这个应用程序执行完毕
之后才执行程序的下一步,请问怎么实现?
另外,能不能在程序里与被调用的应用程序交互(例如多次向应用程序输入参数,
取得应用程序的执行结果等)

解决方案 »

  1.   

    1/
    int i=ShellExecute(NULL, _T("open"),strName, NULL,NULL,SW_SHOW);
    if(i==你要的值)
    {
    }
      

  2.   

    SHELLEXECUTEINFO ShExecInfo = {0};
    ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
    ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
    ShExecInfo.hwnd = NULL;
    ShExecInfo.lpVerb = NULL;
    ShExecInfo.lpFile = "c:\\MyProgram.exe";
    ShExecInfo.lpParameters = "";
    ShExecInfo.lpDirectory = NULL;
    ShExecInfo.nShow = SW_SHOW;
    ShExecInfo.hInstApp = NULL;
    ShellExecuteEx(&ShExecInfo);
    WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
    或: PROCESS_INFORMATION ProcessInfo; 
    STARTUPINFO StartupInfo; //This is an [in] parameter
    ZeroMemory(&StartupInfo, sizeof(StartupInfo));
    StartupInfo.cb = sizeof StartupInfo ; //Only compulsory field
    if(CreateProcess("c:\\winnt\\notepad.exe", NULL, 
        NULL,NULL,FALSE,0,NULL,
        NULL,&StartupInfo,&ProcessInfo))

        WaitForSingleObject(ProcessInfo.hProcess,INFINITE);
        CloseHandle(ProcessInfo.hThread);
        CloseHandle(ProcessInfo.hProcess);
    }  
    else
    {
        MessageBox("The process could not be started...");
    }