Creates a new process.
Example
Do not run below example code just to see what happens next. Many methods seriously affect your system. Always make sure you actually understand what the method and the code do.
# define the arguments you want to submit to the method
# remove values that you do not want to submit
# make sure you replace values with meaningful content before running the code
# see section "Parameters" below for a description of each argument.
$arguments = @{
CommandLine = 'someText' # replace 'someText' with meaningful text
CurrentDirectory = 'someText' # replace 'someText' with meaningful text
ProcessStartupInformation = 12345 # replace 12345 with a meaningful value
}
Invoke-CimMethod -ClassName Win32_Process -Namespace Root/CIMV2 -MethodName Create -Arguments $arguments |
Add-Member -MemberType ScriptProperty -Name ReturnValueFriendly -Passthru -Value {
switch ([int]$this.ReturnValue)
{
0 {'Successful completion'}
2 {'Access denied'}
3 {'Insufficient privilege'}
8 {'Unknown failure'}
9 {'Path not found'}
21 {'Invalid parameter'}
default {'Unknown Error '}
}
}
To run this method on one or more remote systems, use New-CimSession
:
$ComputerName = 'server12','server14' # adjust to your server names
$Credential = Get-Credential # submit a user account with proper permissions
# define the arguments you want to submit to the method
# remove values that you do not want to submit
# make sure you replace values with meaningful content before running the code
# see section "Parameters" below for a description of each argument.
$arguments = @{
CommandLine = 'someText' # replace 'someText' with meaningful text
CurrentDirectory = 'someText' # replace 'someText' with meaningful text
ProcessStartupInformation = 12345 # replace 12345 with a meaningful value
}
$session = New-CimSession -ComputerName $ComputerName -Credential $Credential
Invoke-CimMethod -ClassName Win32_Process -Namespace Root/CIMV2 -MethodName Create -Arguments $arguments -CimSession $session |
Add-Member -MemberType ScriptProperty -Name ReturnValueFriendly -Passthru -Value {
switch ([int]$this.ReturnValue)
{
0 {'Successful completion'}
2 {'Access denied'}
3 {'Insufficient privilege'}
8 {'Unknown failure'}
9 {'Path not found'}
21 {'Invalid parameter'}
default {'Unknown Error '}
}
}
Remove-CimSession -CimSession $session
Learn more about
Invoke-CimMethod
and invoking WMI methods.
Syntax
uint32 Create(
[in] string CommandLine,
[in] string CurrentDirectory,
[in] Win32_ProcessStartup ProcessStartupInformation,
[out] uint32 ProcessId
);
Parameters
Name | Type | Description |
---|---|---|
CommandLine | String | The CommandLine parameter specifies the command line to execute. The system adds a null character to the command line, trimming the string if necessary, to indicate which file was actually used. A fully qualified path must be specified in cases where the program to be launched is not in the search path of Winmgmt (not the user’s path). |
CurrentDirectory | String | The CurrentDirectory parameter specifies the current drive and directory for the child process. The string requires that the current directory resolves to a known path. A user can specify an absolute path or a path relative to the current working directory. If this parameter is NULL, the new process will have the same path as the calling process. This option is provided primarily for shells that must start an application and specify the application’s initial drive and working directory. |
ProcessStartupInformation | Object | The ProcessStartupInformation parameter represents the startup configuration of a Win32 process. It includes information about displaying the window, characteristics of a console application, and handling errors. Note that in Windows XP and beyond, the WinstationDesktop string property (which previously defaulted to “winsta0\default”) is ignored in all cases. The value used in place of this parameter is an empty string (“”). |
Return Value
Returns a value of type UInt32. Return values:
$returnValues = @{
0 = 'Successful completion'
2 = 'Access denied'
3 = 'Insufficient privilege'
8 = 'Unknown failure'
9 = 'Path not found'
21 = 'Invalid parameter'
}
Requirements
To use Win32_Process, the following requirements apply:
PowerShell
Get-CimInstance
was introduced with PowerShell Version 3.0, which in turn was introduced on clients with Windows 8 and on servers with Windows Server 2012.
If necessary, update Windows PowerShell to Windows PowerShell 5.1, or install PowerShell 7 side-by-side.
Operating System
Win32_Process was introduced on clients with Windows Vista and on servers with Windows Server 2008.
Namespace
Win32_Process lives in the Namespace Root/CIMV2. This is the default namespace. There is no need to use the -Namespace parameter in Get-CimInstance
.
Implementation
Win32_Process is implemented in CIMWin32.dll and defined in CIMWin32.mof. Both files are located in the folder C:\Windows\system32\wbem
:
explorer $env:windir\system32\wbem
notepad $env:windir\system32\wbem\CIMWin32.mof