BOOL Success;ZeroMemory( &m_StartupInfo, sizeof(m_StartupInfo ));
ZeroMemory( &m_ProcessInfo, sizeof(m_ProcessInfo ));
ZeroMemory( &m_SecurityAttributes,sizeof( m_SecurityAttributes ));m_SecurityAttributes.nLength = sizeof(SECURITY_ATTRIBUTES);
m_SecurityAttributes.bInheritHandle = TRUE;
m_SecurityAttributes.lpSecurityDescriptor = NULL;Success = CreatePipe
(
&m_PipeReadHandle, // address of variable for read handle
&m_PipeWriteHandle, // address of variable for write handle
&m_SecurityAttributes, // pointer to security attributes
0 // number of bytes reserved for pipe (use default size)
);if ( !Success )
{
ShowLastError(_T("Error creating pipe"));
return 0;
}m_StartupInfo.cb = sizeof(STARTUPINFO);
m_StartupInfo.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
m_StartupInfo.wShowWindow = SW_HIDE;
m_StartupInfo.hStdOutput = m_PipeWriteHandle;
m_StartupInfo.hStdError = m_PipeWriteHandle;Success = CreateProcess
(NULL,// pointer to name of executable module
LPTSTR(m_szCommand), // command line
NULL, // pointer to process security attributes
NULL,// pointer to thread security attributes (use primary thread security attributes)
TRUE, // inherit handles
0, // creation flags
NULL, // pointer to new environment block (use parent's)
m_szCurrentDirectory,// pointer to current directory name
&m_StartupInfo, // pointer to STARTUPINFO
&m_ProcessInfo // pointer to PROCESS_INFORMATION
); if ( !Success )
{
ShowLastError(_T("Error creating process"));
return 0;
}
ZeroMemory( &m_ProcessInfo, sizeof(m_ProcessInfo ));
ZeroMemory( &m_SecurityAttributes,sizeof( m_SecurityAttributes ));m_SecurityAttributes.nLength = sizeof(SECURITY_ATTRIBUTES);
m_SecurityAttributes.bInheritHandle = TRUE;
m_SecurityAttributes.lpSecurityDescriptor = NULL;Success = CreatePipe
(
&m_PipeReadHandle, // address of variable for read handle
&m_PipeWriteHandle, // address of variable for write handle
&m_SecurityAttributes, // pointer to security attributes
0 // number of bytes reserved for pipe (use default size)
);if ( !Success )
{
ShowLastError(_T("Error creating pipe"));
return 0;
}m_StartupInfo.cb = sizeof(STARTUPINFO);
m_StartupInfo.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
m_StartupInfo.wShowWindow = SW_HIDE;
m_StartupInfo.hStdOutput = m_PipeWriteHandle;
m_StartupInfo.hStdError = m_PipeWriteHandle;Success = CreateProcess
(NULL,// pointer to name of executable module
LPTSTR(m_szCommand), // command line
NULL, // pointer to process security attributes
NULL,// pointer to thread security attributes (use primary thread security attributes)
TRUE, // inherit handles
0, // creation flags
NULL, // pointer to new environment block (use parent's)
m_szCurrentDirectory,// pointer to current directory name
&m_StartupInfo, // pointer to STARTUPINFO
&m_ProcessInfo // pointer to PROCESS_INFORMATION
); if ( !Success )
{
ShowLastError(_T("Error creating process"));
return 0;
}
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(STARTUPINFO));
ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));if (CreateProcess(NULL ,"Main.exe",NULL,NULL,FALSE,NORMAL_PRIORITY_CLASS|DETACHED_PROCESS,NULL,NULL,&si,&pi) == 0)
{
DWORD ad = GetLastError();
return;
}
TerminateThread(pi.hThread, 0);