#include <windows.h>
#include <direct.h>
#include <string.h>
#include <tchar.h>
#include <strsafe.h>
void RunTest(TCHAR *AppName, TCHAR *CmdLine)
{
wprintf(L"\nTest Running...\n");
wprintf(L" AppName: %s\n", AppName);
wprintf(L" CmdLine: %s\n", CmdLine);
PROCESS_INFORMATION processInformation;
STARTUPINFO startupInfo;
memset(&processInformation, 0, sizeof(processInformation));
memset(&startupInfo, 0, sizeof(startupInfo));
startupInfo.cb = sizeof(startupInfo);
BOOL result;
TCHAR tempCmdLine[MAX_PATH * 2]; if (CmdLine != NULL)
{
_tcscpy_s(tempCmdLine, MAX_PATH *2, CmdLine);
result = ::CreateProcess(AppName, tempCmdLine, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &startupInfo, &processInformation);
}
else
{
result = ::CreateProcess(AppName, CmdLine, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &startupInfo, &processInformation);
}
if (result == 0)
{
wprintf(L"ERROR: CreateProcess failed!");
}
else
{
WaitForSingleObject( processInformation.hProcess, INFINITE );
CloseHandle( processInformation.hProcess );
CloseHandle( processInformation.hThread );
}
}
int _tmain(int argc, TCHAR* argv[])
{
RunTest(L"C:\\Windows\\System32\\cscipt.exe", L"E:\\mof.vbs");
return 0;
}
"ERROR: CreateProcess failed!" It raises such kind of error at run time
Help me out with how to create a process using
createprocess
function.