Click to See Complete Forum and Search --> : CreateProcess returns ERROR_ALREADY_EXISTS


pw1886
June 1st, 2004, 10:10 PM
Hi, all,

I wrote a program to start another application in NT Service. I called CreateProcess to start the application, however, in my client site, the function returns failure and GetLastError returns ERROR_ALREADY_EXISTS.

Here are what I found:
- I found that there is no other instance of my program (service or the app) in task manager.
- even when I reboot the machine, the same error comes out, I cannot get my application started properly.
- It only happens in my customer site. I cannot repeat that problem on my machines.
- I found that there is little material describing ERROR_ALREADY_EXISTS for CreateProcess. I need help.

Does anyone has encountered this error before? Can you tell me a bit of our experience and what's happening? Thanks for your kindly help.



Here is the portion of the code:

// Start the child process.
if( !CreateProcess(NULL, pszAppPath,
NULL, NULL, FALSE, 0, NULL, NULL, &si, &g_pi) )
{
CHAR szBuf[80];
DWORD dw = GetLastError();
sprintf(szBuf, "MyServiceMain() GetLastError returned %u\n", dw);
printf(szBuf);
return;

}
else
{
printf("MyServiceMain() CreateProcess succeed.\n");
}

// Wait until child process exits.
WaitForSingleObject(g_pi.hProcess, INFINITE);

NoHero
June 2nd, 2004, 12:39 PM
You start an NT Service with CreateProcess ?? I thought this would not work ... You have to use the service API to start a service: Using the "ControlService" function ...

ng

pw1886
June 2nd, 2004, 11:11 PM
Sorry that my description is not clear enough.

I've written a function with service API which is a function to keep track of a process if quit or not. When start service, my service program start the process. If that process quits, the program start the process again.

My problem is now in calling the CreateProcess.

pw1886
June 2nd, 2004, 11:19 PM
I've somehow solved the problem but don't know the reason behind.

What I've done is added double quotes in the App path. Originally, say:

pszAppPath = "c:\\program files\\app\\app.exe";


And now:

pszAppPath = "\"c:\\program files\\app\\app.exe\"";

I got the sense to add a double quote with the following problem:
http://support.microsoft.com/default.aspx?scid=kb;en-us;812486

Maybe the machine in my customer site is upgraded with SOMETHING that no one has admitted did so.