Click here to Skip to main content
15,887,283 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I can't run two exe successfully by CreateProcess method. Each of those two exe's reads some files, registry and database during start up. I have tested the same code to run the system calculator and it is working fine.

When I am trying to run those applications by CreateProcess method, the first application is getting closed automatically after start up and the second one cannot open xx.dat file and failed to read registry and data base. Please see the following code.

C++
PROCESS_INFORMATION processinfo;
STARTUPINFO startUpInfo;
ZeroMemory(&processinfo, sizeof(processinfo));
ZeroMemory(&startUpInfo, sizeof(startUpInfo));
startUpInfo.cb = sizeof(startupInfo);

BOOL bSuccess = CreateProcess(csAppName, NULL, NULL, NULL, FALSE, 0, NULL, NULL, &startUpInfo, &processinfo);


I am getting bSuccess as TRUE always.
Calculator is successfully running with this code but those two applications not.
Also I have tried with "ShellExecute()" and "ShellExecuteEx()" methods with "runas" parameter, but result is the same.
Can anyone help me??????
Posted
Updated 20-May-15 0:17am
v3
Comments
Richard MacCutchan 20-May-15 6:23am    
You need to add some debug code to the programs to see why they do not run in these circumstances.

1 solution

You have assigned to NULL the lpCurrentDirectory parameter, so the default running directory of your executable is the current directory of the calling process.
If the files to read are in another directory the code will fail. Moreover it will fail if a component is not found (see[^]). Because the function returns before the process has finished initialization if a required DLL cannot be located, or fails to initialize, the process is terminated.
You can supply the full path for files to open or you have to supply the current directory from where to run the application.
 
Share this answer
 
v4
Comments
Shubha Debnath 6-Aug-15 8:18am    
CreateProcess successfully starts the application. But the application is getting closed automatically after start up and the second one cannot open xx.dat file and failed to read registry and data base. Please see the following code.

Please note that those are two separate application run individually and shows different behavior.
Frankie-C 6-Aug-15 15:15pm    
Which code? there is nothing.
BTW we cannot understand what happen if you don't show us some code of your exe's.
What is xx.dat file, who create it, where is it created?

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