#include <strsafe.h>
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
char * cbProcessName;
cbProcessName = ( char * ) ( LPCSTR ) &(1:);
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
&(3:) = "";
&(4:) = "";
// Start the child process.
if( !CreateProcess( NULL, // No module name (use command line).
cbProcessName, // Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
0, // No creation flags.
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi ) // Pointer to PROCESS_INFORMATION structure.
)
{
//Create Process failed
LPVOID lpMsgBuf;
LPVOID lpDisplayBuf;
DWORD dw = GetLastError();
// Retrieve the system error message for the last-error code
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf,
0, NULL );
// Display the error message
lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT,(lstrlen((LPCTSTR)lpMsgBuf) + 100) * sizeof(TCHAR));
StringCchPrintf((LPTSTR)lpDisplayBuf,LocalSize(lpDisplayBuf) / sizeof(TCHAR),TEXT("CreateProcess Failed: ErrorCode %d: Msg: %s"),dw, lpMsgBuf);
&(3:) = "ERR";
&(4:) = (LPCTSTR)lpDisplayBuf;
LocalFree(lpMsgBuf);
LocalFree(lpDisplayBuf);
}
else
{
// Wait until child process exits.
WaitForSingleObject( pi.hProcess, INFINITE );
// Get Return Code.
DWORD dwExitCode = -1;
GetExitCodeProcess(pi.hProcess,&dwExitCode);
&(2:) = dwExitCode;
LPVOID lpMsgBuf;
LPVOID lpDisplayBuf;
DWORD dw = GetLastError();
// Retrieve the system error message for the last-error code
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf,
0, NULL );
// Display the error message
lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT,(lstrlen((LPCTSTR)lpMsgBuf) + 100) * sizeof(TCHAR));
StringCchPrintf((LPTSTR)lpDisplayBuf,LocalSize(lpDisplayBuf) / sizeof(TCHAR),TEXT("Code %d: Msg: %s"),dw, lpMsgBuf);
&(4:) = (LPCTSTR)lpDisplayBuf;
LocalFree(lpMsgBuf);
LocalFree(lpDisplayBuf);
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
}
}