BOOL PipeTest()
{
BOOL bret;
SECURITY_ATTRIBUTES sa;
HANDLE hReadPipe, hWritePipe;
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = TRUE;
bret = CreatePipe(&hReadPipe, &hWritePipe, &sa, 0);
if (!bret)
{
return FALSE;
}
STARTUPINFO si;
PROCESS_INFORMATION pi;
si.cb = sizeof(STARTUPINFO);
GetStartupInfo(&si); // SecureZeroMemory(si, sizeof(si));
si.hStdError = hWritePipe;
si.hStdOutput = hWritePipe;
si.wShowWindow = SW_HIDE;
si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
bret = CreateProcess (NULL, /* command line */, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi );
if (!bret)
{
return FALSE;
}
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
CloseHandle(hWritePipe);
char szBuffer[MAX_COMMAND_SIZE + 1];
unsigned long count;
bret = ReadFile(hReadPipe, szBuffer, MAX_COMMAND_SIZE, &count, 0);
CloseHandle(hReadPipe);
if (!bret)
{
return FALSE;
}
/*
do something what you want!
*/
return TRUE;
}
阅读(502) | 评论(0) | 转发(0) |