Kernel32CreateProcess(String, StringBuilder, SecurityAttributes, SecurityAttributes, Boolean, CreateProcessFlags, IntPtr, String, ProcessStartupInfoEx, ProcessInformation) Method
Creates a new process and its primary thread. The new process runs in the security context of the calling process.
If the calling process is impersonating another user,
the new process uses the token for the calling process, not the impersonation token.
To run the new process in the security context of the user represented by the impersonation token,
use the
CreateProcessAsUser(IntPtr, String, StringBuilder, SecurityAttributes, SecurityAttributes, Boolean, CreateProcessFlags, IntPtr, String, ProcessStartupInfo, ProcessInformation) or
CreateProcessWithLogon(String, String, String, ProcessLogonFlags, String, StringBuilder, CreateProcessFlags, IntPtr, String, ProcessStartupInfo, ProcessInformation) function.
Namespace: DevCase.Win32.NativeMethodsAssembly: DevCase.net48 (in DevCase.net48.dll) Version: 6.0.0.0 (6.0)
XMLNS for XAML: Not mapped to an xmlns.
[DllImportAttribute("Kernel32.dll", CharSet = CharSet.Auto, BestFitMapping = false,
ThrowOnUnmappableChar = true, SetLastError = true)]
public static bool CreateProcess(
string applicationName,
[OptionalAttribute] StringBuilder commandLine,
ref SecurityAttributes refProcessAttribs,
ref SecurityAttributes refThreadAttribs,
bool inheritHandles,
CreateProcessFlags createFlags,
IntPtr environment,
string currentDir,
in ProcessStartupInfoEx refStartupInfoEx,
out ProcessInformation refProcessInformation
)
<DllImportAttribute("Kernel32.dll", CharSet := CharSet.Auto, BestFitMapping := false,
ThrowOnUnmappableChar := true, SetLastError := true>]
Public Shared Function CreateProcess (
applicationName As String,
<OptionalAttribute> <OutAttribute> commandLine As StringBuilder,
ByRef refProcessAttribs As SecurityAttributes,
ByRef refThreadAttribs As SecurityAttributes,
inheritHandles As Boolean,
createFlags As CreateProcessFlags,
environment As IntPtr,
currentDir As String,
ByRef refStartupInfoEx As ProcessStartupInfoEx,
<OutAttribute> ByRef refProcessInformation As ProcessInformation
) As Boolean
Dim applicationName As String
Dim commandLine As StringBuilder
Dim refProcessAttribs As SecurityAttributes
Dim refThreadAttribs As SecurityAttributes
Dim inheritHandles As Boolean
Dim createFlags As CreateProcessFlags
Dim environment As IntPtr
Dim currentDir As String
Dim refStartupInfoEx As ProcessStartupInfoEx
Dim refProcessInformation As ProcessInformation
Dim returnValue As Boolean
returnValue = Kernel32.CreateProcess(applicationName,
commandLine, refProcessAttribs,
refThreadAttribs, inheritHandles,
createFlags, environment, currentDir,
refStartupInfoEx, refProcessInformation)
public:
[DllImportAttribute(L"Kernel32.dll", CharSet = CharSet::Auto, BestFitMapping = false,
ThrowOnUnmappableChar = true, SetLastError = true)]
static bool CreateProcess(
String^ applicationName,
[OptionalAttribute] [InAttribute] [OutAttribute] StringBuilder^ commandLine,
SecurityAttributes% refProcessAttribs,
SecurityAttributes% refThreadAttribs,
bool inheritHandles,
CreateProcessFlags createFlags,
IntPtr environment,
String^ currentDir,
[InAttribute] ProcessStartupInfoEx% refStartupInfoEx,
[OutAttribute] ProcessInformation% refProcessInformation
)
[<DllImportAttribute("Kernel32.dll", CharSet = CharSet.Auto, BestFitMapping = false,
ThrowOnUnmappableChar = true, SetLastError = true)>]
static member CreateProcess :
applicationName : string *
[<OptionalAttribute>] commandLine : StringBuilder byref *
refProcessAttribs : SecurityAttributes byref *
refThreadAttribs : SecurityAttributes byref *
inheritHandles : bool *
createFlags : CreateProcessFlags *
environment : IntPtr *
currentDir : string *
refStartupInfoEx : ProcessStartupInfoEx byref *
refProcessInformation : ProcessInformation byref -> bool
No code example is currently available or this language may not be supported.
- applicationName String
-
The name of the module to be executed. This module can be a Windows-based application.
It can be some other type of module (for example, MS-DOS or OS/2)
if the appropriate subsystem is available on the local computer.
The string can specify the full path and file name of the module to execute or it can specify a partial name.
In the case of a partial name, the function uses the current drive and current directory to complete the specification.
The function will not use the search path.
This parameter must include the file name extension; no default extension is assumed.
The applicationName parameter can be NULL.
In that case, the module name must be the first white space–delimited token in the commandLine string.
If you are using a long file name that contains a space,
use quoted strings to indicate where the file name ends and the arguments begin;
otherwise, the file name is ambiguous.
For example, consider the string "c:\program files\sub dir\program name".
This string can be interpreted in a number of ways. The system tries to interpret the possibilities in the following order:
c:\program.exe, c:\program files\sub.exe, c:\program files\sub dir\program.exe, c:\program files\sub dir\program name.exe
If the executable module is a 16-bit application, applicationName should be NULL,
and the string pointed to by commandLine should specify the executable module as well as its arguments.
To run a batch file, you must start the command interpreter;
set applicationName to cmd.exe and set commandLine to the following arguments: "/c", plus the name of the batch file.
- commandLine StringBuilder (Optional)
-
The command line to be executed.
The maximum length of this string is Int16 (32,768 characters),
including the Unicode terminating null character.
If applicationName is NULL,
the module name portion of commandLine is limited to MAX_PATH characters.
The commandLine parameter can be NULL.
In that case, the function uses the string pointed to by applicationName as the command line.
The Unicode version of this function, CreateProcessW, can modify the contents of this string.
Therefore, this parameter cannot be a pointer to read-only memory (such as a const variable or a literal string).
If this parameter is a constant string, the function may cause an access violation.
- refProcessAttribs SecurityAttributes
-
A pointer to a SecurityAttributes structure that determines whether the
returned handle to the new process object can be inherited by child processes.
If refProcessAttribs is NULL, the handle cannot be inherited.
The SecurityDescriptor member specifies a security descriptor for the new process.
If refProcessAttribs is NULL or SecurityDescriptor is Zero,
the process gets a default security descriptor.
- refThreadAttribs SecurityAttributes
-
A pointer to a SecurityAttributes structure that determines whether the
returned handle to the new thread object can be inherited by child processes.
If refThreadAttribs is NULL, the handle cannot be inherited.
The SecurityDescriptor member specifies a security descriptor for the main thread.
If refThreadAttribs is NULL or SecurityDescriptor is Zero,
the thread gets a default security descriptor.
- inheritHandles Boolean
-
If this parameter is ,
each inheritable handle in the calling process is inherited by the new process.
If the parameter is , the handles are not inherited.
Note that inherited handles have the same value and access rights as the original handles.
- createFlags CreateProcessFlags
-
The flags that control the priority class and the creation of the process.
This parameter also controls the new process's priority class,
which is used to determine the scheduling priorities of the process's threads.
- environment IntPtr
-
A pointer to the environment block for the new process.
If this parameter is Zero, the new process uses the environment of the calling process.
An environment block consists of a null-terminated block of null-terminated strings. Each string is in the following form:
name=value\0
Because the equal sign is used as a separator, it must not be used in the name of an environment variable.
The ANSI version of this function, CreateProcessA,
fails if the total size of the environment block for the process exceeds 32,767 characters.
- currentDir String
-
The full path to the current directory for the process. The string can also specify a UNC path.
If this parameter is NULL,
the new process will have the same current drive and directory as the calling process.
(This feature is provided primarily for shells that need to start an application and
specify its initial drive and working directory.)
- refStartupInfoEx ProcessStartupInfoEx
-
A pointer to a ProcessStartupInfoEx structure.
To set extended attributes,
use a ProcessStartupInfoEx structure
and specify ExtendedStartupInfoPresent
in the createFlags parameter.
- refProcessInformation ProcessInformation
-
A pointer to a ProcessInformation structure that receives identification information about the new process.
Boolean
If the function succeeds, the return value is
.
If the function fails, the return value is
.
To get extended error information, call
GetLastWin32Error.
Note that the function returns before the process has finished initialization.
If a required DLL cannot be located or fails to initialize, the process is terminated.
To get the termination status of a process, call
GetExitCodeProcess(IntPtr, UInt32).