Error starting an executable in a new process CreateProcess()

An other time, i'm here with a problem ahahaha
after a lot of time spent in MSDN (https://msdn.microsoft.com/en-us/library/windows/desktop/ms682425(v=vs.85).aspx) i created this part of code that open a file called system.exe
the code is compiled without any error but the file doesn't start. I've checked if the file exist, it exist but doesn't startup!
why? Thanks

1
2
3
4
5
6
7
8
9
void start(string path){
    STARTUPINFO Startupinf;
    PROCESS_INFORMATION Processinfo;
    cout<<path;
    if(!CreateProcess(path.c_str(),NULL,NULL,NULL,FALSE,NORMAL_PRIORITY_CLASS,NULL,path.c_str(),&Startupinf,&Processinfo)){
        cout<<"\n\n\nERROR 3x02";
    }

}

I think you need to initialize Startupinf properly. Try this code:
1
2
3
4
5
6
7
8
9
10
11
12
13
void start(string path)
{
    STARTUPINFO Startupinf = {0};
    PROCESS_INFORMATION Processinfo = {0};

    Startupinf.cb = sizeof(STARTUPINFO);
    
    if(!CreateProcess(path.c_str(),NULL,NULL,NULL,FALSE,NORMAL_PRIORITY_CLASS,
        NULL,0,&Startupinf,&Processinfo))
    {
      cout << "\n\nERROR: " << GetLastError();
    }
}
closed account (E0p9LyTq)
There is another MSDN page that gives an example of creating a child process:

https://msdn.microsoft.com/en-us/library/windows/desktop/ms682512%28v=vs.85%29.aspx
Already done it
The GetLastError gives me the error 267, DIRECTORY_ERROR

I don't understand why, the directory exist .

You are talking about child process right?
I need to create a program that start an other program at the startup because if I put the other program in startup folder it doesn't work
So I need to start this other program at the startup just as the user is DoubleClicking it! Is this the right way?
closed account (E0p9LyTq)
So what is the exact directory string you are using?

C:\SomeDirectory\SomeApp.exe won't work. It has to be C:\\SomeDirectory\\SomeApp.exe.
It is possible that this program requires specific things set up. Use ShellExecute(Ex) and specify working directory exactly the same as the child EXE.

Why the target program does not run directly on startup ? Maybe is made by the developers to only be started from explorer.
Topic archived. No new replies allowed.