2.1.25.4 CreateProcess


Description

The CreateProcess function creates a new process and its primary thread. The new process executes the specified executable file. For more info please check: http://msdn.microsoft.com/en-us/library/ms682425(VS.85).aspx

Syntax

BOOL CreateProcess( LPCSTR lpApplicationName, LPSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCSTR lpCurrentDirectory, LPSTARTUPINFO lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation )

Parameters

lpApplicationName
[input]The name of the module to be executed. This module can be a Windows-based application. It
lpCommandLine
[modify]This parameter is optional. The command line to be executed.
lpProcessAttributes
[input]A pointer to a SECURITY_ATTRIBUTES structure that determines whether the returned handle to the new process object can be inherited by child processes.
If lpProcessAttributes is NULL, the handle cannot be inherited.
lpThreadAttributes
[input]A pointer to a SECURITY_ATTRIBUTES structure that determines whether the returned handle to the new thread object can be inherited by child processes.
If lpThreadAttributes is NULL, the handle cannot be inherited.
bInheritHandles
[input]If this parameter TRUE, each inheritable handle in the calling process is inherited by the new process. If the parameter is FALSE, the handles are not inherited.
dwCreationFlags
[input]The flags that control the priority class and the creation of the process.
lpEnvironment
[input]A pointer to the environment block for the new process. If this parameter is NULL, the new process uses the environment of the calling process.
lpCurrentDirectory
[input]The full path to the current directory for the process.
lpStartupInfo
[input]A pointer to a STARTUPINFO or STARTUPINFOEX structure.
lpProcessInformation
[input]A pointer to a PROCESS_INFORMATION structure that receives identification information about the new process.

Return

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError

Examples

EX1

   void test_create_process()
    {
        STARTUPINFO            sinfo;        
        PROCESS_INFORMATION    pinfo;        
        memset(&sinfo, 0, sizeof(STARTUPINFO));
        memset(&pinfo, 0, sizeof(PROCESS_INFORMATION));
        // test control wShowWindow
        sinfo.dwFlags = STARTF_USESHOWWINDOW;
        sinfo.wShowWindow = SW_SHOWMAXIMIZED;
        BOOL bSucess = CreateProcess("C:\\Windows\\notepad.exe", NULL, NULL, NULL, FALSE, CREATE_DEFAULT_ERROR_MODE, NULL, NULL, &sinfo, &pinfo);
    }

Remark

See Also

TerminateProcess , GetExitCodeProcess, ShellExecute, WinExec

Header to Included

origin.h

Reference