Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
//#include "stdafx.h"

#include <windows.h>

#include <direct.h>
#include <string.h>
#include <tchar.h>
#include <strsafe.h>

void RunTest(TCHAR *AppName, TCHAR *CmdLine)
{
//  Appname="C:\\Windows\\System32\\cscipt.exe";
    //CmdLine="E:\\mof.vbs";
    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];  //Needed since CreateProcessW may change the contents of CmdLine
    if (CmdLine != NULL)
    {
         //wprintf(L"ERROR: CreateProcess failed!");
        _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[])
{
    //Assumes ParamTest.exe is in the current working directory
    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.
Posted
Updated 19-May-11 18:45pm
v2
Comments
ShilpiP 20-May-11 2:14am    
Hi Vinayak,
1) Your command is like "C:\\Windows\\System32\\cscipt.exe E:\\mof.vbs".
Is your executalbe is using "E:\\mof.vbs" as an argument??

1 solution

I think it's "cscript.exe", not "cscipt.exe". Try that ;)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900