void CpipeMFCDlg::OnBnClickedOk()
{
HANDLE hReadPipe1, hWritePipe1;
SECURITY_ATTRIBUTES sa;
sa.bInheritHandle = TRUE;
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = NULL;
// create stdout pipe
if (!CreatePipe(&hReadPipe1, &hWritePipe1, &sa, sizeof(sa))) return ;
// create stdin pipe
HANDLE hReadPipe2, hWritePipe2;
if (!CreatePipe(&hReadPipe2, &hWritePipe2, &sa, sizeof(sa))) return ;
// Fill the struct STARTUPINFO
STARTUPINFO si;
GetStartupInfo(&si);
si.cb = sizeof(STARTUPINFO);
si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES ;
si.wShowWindow = SW_SHOWNORMAL;
si.hStdError = hWritePipe1;
si.hStdInput = hReadPipe2;
si.hStdOutput = hWritePipe1;
si.lpTitle = "CMD";
// create process
PROCESS_INFORMATION pi;
if (!CreateProcess("c:\\WINDOWS\\system32\\cmd.exe",NULL,NULL,NULL, TRUE, CREATE_NEW_CONSOLE,
NULL,NULL,&si, &pi)) return ;
DWORD w;
if (!WriteFile(hWritePipe2,"regedit",7,&w,0)) return;
}
}
проблема с пайпми
Задача - запустить regedit, например.