CreateProcess method of the MSFT_MTProcess class

Create a new process.

Syntax

uint32 CreateProcess(
  [in]  string CommandLine,
  [in]  uint32 WaitMilliseconds,
  [out] uint32 ProcessId,
  [out] string ActualCommandLine
);

Parameters

CommandLine [in]

The command line to be run.

WaitMilliseconds [in]

Time, in milliseconds, to wait for the process to end.

ProcessId [out]

Returns the process identifier of the new process.

ActualCommandLine [out]

Returns the actual command line used to start the process, with any environment variables expanded.

Return value

Returns the exit code of the process, or 259 if the process did not exit before WaitMilliseconds elapsed.

Remarks

The command line supports parameters and environment variables. If WaitMilliseconds is specified, this method will return the exit code of the process. If the process has not exited within the time specified, this method will return code 259. This method can be forced to wait indefinitely for the process to exit by specifying 0xffffffff (4294967295) in WaitMilliseconds.

Examples

This PowerShell snippet connects to the TestSrv1 computer and enumerates the processes, creates a new Cmd.exe process, and then enumerates the processes again.

$option = New-CimSessionOption -Protocol WSMan
$session = New-CimSession -ComputerName TestSrv1 -SessionOption $option -Credential (Get-Credential)
Get-CimInstance  -CimSession $session -Namespace Root/Microsoft/Windows/ManagementTools -ClassName MSFT_MTProcess | Select Name,CpuPercent,ProcessId
Invoke-CimMethod -CimSession $session -Namespace Root/Microsoft/Windows/ManagementTools -ClassName MSFT_MTProcess -MethodName CreateProcess -Arguments @{ CommandLine = "Cmd.exe" }
Get-CimInstance  -CimSession $session -Namespace Root/Microsoft/Windows/ManagementTools -ClassName MSFT_MTProcess | Select Name,CpuPercent,ProcessId

Requirements

Minimum supported client
None supported
Minimum supported server
Windows Server 2016
Namespace
Root\Microsoft\Windows\ManagementTools
MOF
MtTmProv.mof
DLL
MtTmProv.dll

See also

MSFT_MTProcess