Saturday, 14 September 2013

C++ CreateProcess - System Error #2 can't find file - what is wrong with my file path?

C++ CreateProcess - System Error #2 can't find file - what is wrong with
my file path?

I am trying to open a pdf via firefox with CreateProcess(), I am a
beginner and know nothing about using CreateProcess, but in my last
question someone pointed out the MSDN on it... it shows that:
To run a batch file, you must start the command interpreter;
set lpApplicationName to cmd.exe and set lpCommandLine to the
following arguments: /c plus the name of the batch file.
Therefore I created a batch file that runs perfectly fine with the
system() command, there are no problems with the batch file.
I can't figure out why the system can't find the file and I don't know if
its the batch file, the exe in the batch file, the pdf doc in the batch
file or the location of cmd.exe... Any help is greatly appreciated...
void openPDF(char scansQueue[][MAX_NAME], int index)
{
// build batch file
char openPath[300];
char procCommand[MAX_NAME]="C:\\firefox";
char cmdEXE[MAX_NAME]="C:\\Windows\\System32\\cmd.exe";
fstream outfile;
outfile.open("C:\\firefox.bat");
copyCString(openPath,"\"C:\\Program Files (x86)\\Mozilla
Firefox\\firefox.exe\"");
outfile << openPath;
outfile << ' ';
copyCString(openPath,"\"C:\\Scans\\");
catArray(openPath,scansQueue[index]);
catArray(openPath,"\"");
STARTUPINFOW si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
cout<<"PROCESS ATTEMPT"<<endl;
if(!CreateProcess((LPCTSTR)cmdEXE ,(LPWSTR)procCommand, NULL, NULL, false,
0, NULL, NULL, &si, &pi))cout << GetLastError();cout<<"PROCESS FAILED TO
EXECUTE!!!";
}

No comments:

Post a Comment