CreateProcessW Function

Function

Creates a new process and its primary thread. The new process is run within the security context of the calling process.

Syntax


BOOL CreateProcessW(
  [in, optional]      LPCWSTR               lpApplicationName,
  [in, out, optional] LPWSTR                lpCommandLine,
  [in, optional]      LPSECURITY_ATTRIBUTES lpProcessAttributes,
  [in, optional]      LPSECURITY_ATTRIBUTES lpThreadAttributes,
  [in]                BOOL                  bInheritHandles,
  [in]                DWORD                 dwCreationFlags,
  [in, optional]      LPVOID                lpEnvironment,
  [in, optional]      LPCWSTR               lpCurrentDirectory,
  [in]                STARTUPINFOW          *lpStartupInfo,
  [out]               LPPROCESS_INFORMATION lpProcessInformation
);
            

Parameters

Parameter Description
lpApplicationName The name of the module to be executed. The string must be a full path or a relative path. If this parameter is NULL, the module name is taken from the first token in the lpCommandLine string. This parameter can be NULL.
lpCommandLine The command line string for the new process. This string is NULL-terminated.
lpProcessAttributes A pointer to a SECURITY_ATTRIBUTES structure that specifies the security attributes of the new process. If NULL, the process gets a default security descriptor.
lpThreadAttributes A pointer to a SECURITY_ATTRIBUTES structure that specifies the security attributes of the new thread. If NULL, the thread gets a default security descriptor.
bInheritHandles If this parameter is TRUE, each handle inherited by the new process is a duplicate of the handle of the calling process. Otherwise, the handles are not inherited.
dwCreationFlags Flags that control the priority class and behavior of the new process.
lpEnvironment A pointer to a null-terminated list of null-terminated strings, which specifies the environment for the new process.
lpCurrentDirectory A null-terminated string that specifies the full path for the current directory for the process.
lpStartupInfo A pointer to a STARTUPINFOW structure that specifies the window station, family, startup info, and main window handle.
lpProcessInformation A pointer to a PROCESS_INFORMATION structure that receives identification information about the new process.

Return Value

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.

Remarks

The CreateProcessW function creates a new process to execute the specified application. The new process is created with a new message-coalescing message queue, a security token, and a primary thread. The calling process can specify various attributes for the new process, including its priority class, security, and environment.

The lpCommandLine parameter is used to pass command-line arguments to the new process. If lpApplicationName is NULL, the first token in lpCommandLine is taken as the name of the module to be executed. This token must be the full path to the executable file.

The dwCreationFlags parameter can be used to specify various creation flags, such as CREATE_NEW_CONSOLE to create a new console window for the process, or DETACHED_PROCESS to run the process without a console.

The lpStartupInfo parameter provides information about the initial window appearance of the process. The STARTUPINFOW structure contains fields such as dwFlags, cxWindow, cyWindow, and lpDesktop.

The lpProcessInformation parameter receives information about the newly created process, including its process handle, thread handle, process identifier, and thread identifier.

Requirements

Minimum supported client Windows 2000 Professional
Minimum supported server Windows 2000 Server
Target Platform Windows
Header processthreadsapi.h
Library Kernel32.lib
DLL Kernel32.dll