CreateProcess (coredll)
Last changed: hfr@hfrmobile.com-80.109.238.224

.
Summary
This function creates a new process.

C# Signature:

[DllImport("coredll.dll", SetLastError=true)]
static extern bool CreateProcess( String imageName,
            String cmdLine,
            IntPtr lpProcessAttributes,
            IntPtr lpThreadAttributes,
            bool boolInheritHandles,
            Int32 dwCreationFlags,
            IntPtr lpEnvironment,
            IntPtr lpszCurrentDir,
            byte [] si,
            ProcessInfo pi );

VB Signature:

Declare Function CreateProcess Lib "coredll.dll" (ByVal imageName As String, ByVal cmdLine As String, ByVal lpProcessAttributes As IntPtr, ByVal lpThreadAttributes As IntPtr, ByVal boolInheritHandles As Int32, ByVal dwCreationFlags As Int32, ByVal lpEnvironment As IntPtr, ByVal lpszCurrentDir As IntPtr, ByVal si As Byte(), ByVal pi As ProcessInfo) As Integer

User-Defined Types:

C#

public class ProcessInfo
{
    public IntPtr hProcess;
    public IntPtr hThread;
    public Int32 ProcessId;
    public Int32 ThreadId;
}

VB

Public Class ProcessInfo
    Public hProcess As IntPtr
    Public hThread As IntPtr
    Public ProcessId As Int32
    Public ThreadId As Int32
End Class

Notes:

None.

Tips & Tricks:

You will need the above ProcessInfo class and may also want to use GetLastError and WaitForSingleObject.

Sample Code:

C# Sample usage:

ProcessInfo pi = new ProcessInfo();
byte [] si = new byte[128];
bool result = CreateProcess("calc.exe", "", IntPtr.Zero, IntPtr.Zero,0, false, IntPtr.Zero, IntPtr.Zero, si, pi);

VB Sample Usage:

Dim pi As New ProcessInfo
Dim si(128) As Byte
Dim result As Int32

result = CreateProcess("calc.exe", "", IntPtr.Zero, IntPtr.Zero, 0, 0, IntPtr.Zero, IntPtr.Zero, si, pi)

Alternative Managed API:

Do you know one? Please contribute it!

Documentation