I have to execute an .exe which is available on some drive. How can I do this using C++?
I am doing it like this:
#include <stdio.h>
#include <conio.h>
#include <windows.h>
void main()
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
if(!CreateProcess(L"c:\\DOTNET.exe",NULL,NULL, NULL,FALSE, 0,NULL,NULL,&si,&pi ) )
{
printf( "CreateProcess failed (%d).\n", GetLastError() );
}
else
{
printf("Prcess Creation Success");
}
WaitForSingleObject( pi.hProcess, INFINITE );
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
getch();
}
But every time, it is showing this error:
process creation failed with error code 2 (i.e can not find the path specified)
But I place the DOTNET.exe at c:\DOTNET.exe only.
What is wrong in this code?
I’ve just tested your code and it’s working here with :
A C++/Win32 solution for your C/Win32 code 🙂