CommandLineEventConsumer

Command Line Event Consumer

The CommandLineEventConsumer class starts an arbitrary process in the local system when an event is delivered to it.

On this page

Main example

List instances

# All instances of CommandLineEventConsumer, with the main properties
Get-CimInstance -ClassName CommandLineEventConsumer -Namespace 'root/subscription' |
    Select-Object -Property Name, ExecutablePath, CommandLineTemplate, CreateNewConsole

Examples

Filter with WQL

# WQL filter evaluated by the provider: FillAttributes = 1 (blue foreground)
$cimParameters = @{
    ClassName = 'CommandLineEventConsumer'
    Namespace = 'root/subscription'
    Filter    = 'FillAttributes = 1'
}
Get-CimInstance @cimParameters |
    Select-Object -Property Name, ExecutablePath, CommandLineTemplate, CreateNewConsole

The filter is evaluated by the WMI provider: less data is transferred than with Where-Object.

Decode numeric values

# Lookup table for FillAttributes (values documented by Microsoft)
$fillAttributesName = @{
    1 = 'blue foreground'
    2 = 'green foreground'
    4 = 'red foreground'
    8 = 'foreground intensity'
    16 = 'blue background'
    32 = 'green background'
    64 = 'red background'
    128 = 'background intensity'
}
# Lookup table for Priority (values documented by Microsoft)
$priorityName = @{
    32 = 'Indicates a normal process without scheduling needs'
    64 = 'Indicates a process whose threads run only when the system…'
    128 = 'Indicates a process that performs high-priority, time…'
    256 = 'Indicates a process that has the highest possible priority'
}

Get-CimInstance -ClassName CommandLineEventConsumer -Namespace 'root/subscription' |
    Select-Object -Property @(
        'Name'
        'ExecutablePath'
        'CommandLineTemplate'
        'CreateNewConsole'
        @{ Name = 'FillAttributes'; Expression = { $fillAttributesName[[int]$_.FillAttributes] } }
        @{ Name = 'Priority'; Expression = { $priorityName[[int]$_.Priority] } }
    )

Query a remote computer (CIM session)

review before running
# Name of the remote computer
$computerName = 'SERVER01'
# The CIM session (WSMan by default) can be reused for several queries
$cimSession = New-CimSession -ComputerName $computerName
try {
    $cimParameters = @{
        CimSession = $cimSession
        ClassName  = 'CommandLineEventConsumer'
        Namespace  = 'root/subscription'
    }
    Get-CimInstance @cimParameters |
        Select-Object -Property Name, ExecutablePath, CommandLineTemplate, CreateNewConsole
} finally {
    Remove-CimSession -CimSession $cimSession
}

WSMan (WinRM) is used by default. For a host without WinRM, create the session with -SessionOption (New-CimSessionOption -Protocol Dcom). Add -Credential to use another account.

Show the class structure

# Class structure: properties, types and flags (Key, ReadOnly…)
$cimClass = Get-CimClass -ClassName CommandLineEventConsumer -Namespace 'root/subscription'
$cimClass.CimClassProperties |
    Select-Object -Property Name, CimType, Flags

Properties

28 of 28 properties
NameTypeAccessDescription
CommandLineTemplatestringread

Standard string template that specifies the process to be started. This property can be NULL, and the ExecutablePath property is used as the command line.

Code
# Value of CommandLineTemplate for each instance
$cimParameters = @{
    ClassName = 'CommandLineEventConsumer'
    Namespace = 'root/subscription'
    Property  = @('Name', 'CommandLineTemplate')
}
Get-CimInstance @cimParameters |
    Select-Object -Property Name, CommandLineTemplate
CreateNewConsolebooleanread

Not used. If a value is assigned to this property, a tracing message is generated. For more information, see Tracing WMI Activity.

Code
# Value of CreateNewConsole for each instance
$cimParameters = @{
    ClassName = 'CommandLineEventConsumer'
    Namespace = 'root/subscription'
    Property  = @('Name', 'CreateNewConsole')
}
Get-CimInstance @cimParameters |
    Select-Object -Property Name, CreateNewConsole
CreateNewProcessGroupbooleanread

If True, the new process is the root process of a new process group. The process group includes all processes that are descendants of this root process. The process identifier of the new process group is the same as this process identifier. Process groups are used by the GenerateConsoleCtrlEvent method to enable sending a CTRL+C or CTRL+BREAK signal to a group of console processes.

Code
# Value of CreateNewProcessGroup for each instance
$cimParameters = @{
    ClassName = 'CommandLineEventConsumer'
    Namespace = 'root/subscription'
    Property  = @('Name', 'CreateNewProcessGroup')
}
Get-CimInstance @cimParameters |
    Select-Object -Property Name, CreateNewProcessGroup
CreateSeparateWowVdmbooleanread

If True, the new process runs in a private Virtual DOS Machine (VDM). This is only valid when starting an application running on a 16-bit Windows operating system. If set to False, all applications running on a 16-bit Windows operating system run as threads in a single, shared VDM. For more information, see the Remarks section of this topic.

Code
# Value of CreateSeparateWowVdm for each instance
$cimParameters = @{
    ClassName = 'CommandLineEventConsumer'
    Namespace = 'root/subscription'
    Property  = @('Name', 'CreateSeparateWowVdm')
}
Get-CimInstance @cimParameters |
    Select-Object -Property Name, CreateSeparateWowVdm
CreateSharedWowVdmbooleanread

If True, the CreateProcess method runs the new process in the shared Virtual DOS Machine (VDM). This property can override the DefaultSeparateVDM switch in the Windows section of Win.ini if set to True. For more information, see the Remarks section of this topic.

Code
# Value of CreateSharedWowVdm for each instance
$cimParameters = @{
    ClassName = 'CommandLineEventConsumer'
    Namespace = 'root/subscription'
    Property  = @('Name', 'CreateSharedWowVdm')
}
Get-CimInstance @cimParameters |
    Select-Object -Property Name, CreateSharedWowVdm
CreatorSIDuint8[]read

Security identifier (SID) that uniquely identifies the user who creates a filter. WMI stores the SID of the user who creates an instance of __EventConsumer or the Administrator SID, depending on the operating system. For more information, see Binding an Event Filter with a Logical Consumer and Monitoring and Responding to Events with Standard Consumers.

Code
# Value of CreatorSID for each instance
# CreatorSID is an array: -ExpandProperty returns its items one by one
$cimParameters = @{
    ClassName = 'CommandLineEventConsumer'
    Namespace = 'root/subscription'
    Property  = 'CreatorSID'
}
Get-CimInstance @cimParameters |
    Select-Object -ExpandProperty CreatorSID
DesktopNamestringread

Not used. If a value is assigned to this property a tracing message is generated. For more information, see Tracing WMI Activity.

Code
# Value of DesktopName for each instance
$cimParameters = @{
    ClassName = 'CommandLineEventConsumer'
    Namespace = 'root/subscription'
    Property  = @('Name', 'DesktopName')
}
Get-CimInstance @cimParameters |
    Select-Object -Property Name, DesktopName
ExecutablePathstringread

Module to execute. The string can specify the full path and file name of the module to execute, or it can specify a partial name. If a partial name is specified, the current drive and current directory are assumed.

The ExecutablePath property can be NULL. In that case, the module name must be the first white space-delimited token in the CommandLineTemplate property value. If using a long file name that contains a space, use quoted strings to indicate where the file name ends and the arguments begin to clarify the file name.

Note: Because the CommandLineTemplate property can be a template where the module to execute is supplied by a variable, a NULLExecutablePath property permits the module that is specified in the parameter to execute, and then it is out of your control. Always set the ExecutablePath property in the CommandLineEventConsumer registration to include the required executable, which avoids overwriting by events parameters. If you must use a template and variable to specify the module to execute, be careful about who is granted full write privilege in the namespace.

Code
# Value of ExecutablePath for each instance
$cimParameters = @{
    ClassName = 'CommandLineEventConsumer'
    Namespace = 'root/subscription'
    Property  = @('Name', 'ExecutablePath')
}
Get-CimInstance @cimParameters |
    Select-Object -Property Name, ExecutablePath
FillAttributeuint32read

Specifies the initial text and background colors if a new console window is created in a console application

Code
# Value of FillAttribute for each instance
$cimParameters = @{
    ClassName = 'CommandLineEventConsumer'
    Namespace = 'root/subscription'
    Property  = @('Name', 'FillAttribute')
}
Get-CimInstance @cimParameters |
    Select-Object -Property Name, FillAttribute
FillAttributesuint32read/write

Initial text and background colors, if a new console window is created in a console application. This property is ignored in a GUI application. The value can be any combination of the following values.

For example, the following combinations produce red text on a white background:

```mof

0x4 | 0x40 | 0x20 | 0x10

```

or

```mof

0x74

```

Values (8)
ValueLabelDescription
1blue foreground
2green foreground
4red foreground
8foreground intensity
16blue background
32green background
64red background
128background intensity
Code
# Value of FillAttributes for each instance
# Lookup table for FillAttributes (values documented by Microsoft)
$fillAttributesName = @{
    1 = 'blue foreground'
    2 = 'green foreground'
    4 = 'red foreground'
    8 = 'foreground intensity'
    16 = 'blue background'
    32 = 'green background'
    64 = 'red background'
    128 = 'background intensity'
}
$cimParameters = @{
    ClassName = 'CommandLineEventConsumer'
    Namespace = 'root/subscription'
    Property  = @('Name', 'FillAttributes')
}
Get-CimInstance @cimParameters |
    Select-Object -Property @(
        'Name'
        @{ Name = 'FillAttributes'; Expression = { $fillAttributesName[[int]$_.FillAttributes] } }
    )

Warning. Changes the system: check with -WhatIf first. An elevated console is often required.

# Warning: changes FillAttributes on the instance. -WhatIf shows the operation without running it.
# Target instance
$instanceParameters = @{
    ClassName = 'CommandLineEventConsumer'
    Namespace = 'root/subscription'
    Filter    = "Name = 'Example'"
}
$instance = Get-CimInstance @instanceParameters
$setParameters = @{
    InputObject = $instance
    Property    = @{ FillAttributes = 1 }
    WhatIf      = $true  # Remove this line to actually apply the change
}
Set-CimInstance @setParameters
ForceOffFeedbackbooleanread

If True, the feedback cursor is forced off while the process is starting. The normal cursor is displayed.

Code
# Value of ForceOffFeedback for each instance
$cimParameters = @{
    ClassName = 'CommandLineEventConsumer'
    Namespace = 'root/subscription'
    Property  = @('Name', 'ForceOffFeedback')
}
Get-CimInstance @cimParameters |
    Select-Object -Property Name, ForceOffFeedback
ForceOnFeedbackbooleanread

If True, the cursor is in feedback mode for two seconds after CreateProcess is called. During those two seconds, if the process makes the first GUI call, the system gives five more seconds to the process. During those five seconds, if the process shows a window, the system gives another five seconds to the process to finish drawing the window.

Code
# Value of ForceOnFeedback for each instance
$cimParameters = @{
    ClassName = 'CommandLineEventConsumer'
    Namespace = 'root/subscription'
    Property  = @('Name', 'ForceOnFeedback')
}
Get-CimInstance @cimParameters |
    Select-Object -Property Name, ForceOnFeedback
KillTimeoutuint32read

Number, in seconds, that the WMI service waits before killing a process 0 (zero) indicates a process is not to be killed. Killing a process prevents a process from running indefinitely.

Code
# Value of KillTimeout for each instance
$cimParameters = @{
    ClassName = 'CommandLineEventConsumer'
    Namespace = 'root/subscription'
    Property  = @('Name', 'KillTimeout')
}
Get-CimInstance @cimParameters |
    Select-Object -Property Name, KillTimeout
MachineNamestringread

Name of the computer to which Windows Management Instrumentation (WMI) sends events.

Code
# Value of MachineName for each instance
$cimParameters = @{
    ClassName = 'CommandLineEventConsumer'
    Namespace = 'root/subscription'
    Property  = @('Name', 'MachineName')
}
Get-CimInstance @cimParameters |
    Select-Object -Property Name, MachineName
MaximumQueueSizeuint32read

Maximum queue for a specific consumer, in bytes.

Code
# Value of MaximumQueueSize for each instance
$cimParameters = @{
    ClassName = 'CommandLineEventConsumer'
    Namespace = 'root/subscription'
    Property  = @('Name', 'MaximumQueueSize')
}
Get-CimInstance @cimParameters |
    Select-Object -Property Name, MaximumQueueSize
Name keystringread

Unique name of a consumer.

Code
# Value of Name for each instance
$cimParameters = @{
    ClassName = 'CommandLineEventConsumer'
    Namespace = 'root/subscription'
    Property  = 'Name'
}
Get-CimInstance @cimParameters |
    Select-Object -Property Name
Prioritysint32read

Scheduling priority level of the process threads. The following list lists the priority levels available.

Values (4)
ValueLabelDescription
32Indicates a normal process without scheduling needs.
64Indicates a process whose threads run only when the system is idle, and are preempted by the threads of any process running in a higher priority class. An example is a screen saver. The idle priority class is inherited by child processes.
128Indicates a process that performs high-priority, time critical tasks. The threads of a high-priority class process preempts the threads of normal-priority or idle-priority class processes. An example is the Task List, which must respond quickly when called by the user regardless of the load on the system. Use extreme care when using the high-priority class, because a CPU-bound application with a high-priority class can use nearly all available cycles.
256Indicates a process that has the highest possible priority. The threads of a real-time priority class process preempt the threads of all other processes, including operating system processes that perform important tasks. For example, a real-time process that executes for more than a brief interval can cause disk caches not to flush, or cause the mouse to be unresponsive.
Code
# Value of Priority for each instance
# Lookup table for Priority (values documented by Microsoft)
$priorityName = @{
    32 = 'Indicates a normal process without scheduling needs'
    64 = 'Indicates a process whose threads run only when the system…'
    128 = 'Indicates a process that performs high-priority, time…'
    256 = 'Indicates a process that has the highest possible priority'
}
$cimParameters = @{
    ClassName = 'CommandLineEventConsumer'
    Namespace = 'root/subscription'
    Property  = @('Name', 'Priority')
}
Get-CimInstance @cimParameters |
    Select-Object -Property @(
        'Name'
        @{ Name = 'Priority'; Expression = { $priorityName[[int]$_.Priority] } }
    )
RunInteractivelybooleanread

If True, the process is launched in the interactive WinStation. If False, the process is launched in the default service WinStation. This property overrides the DesktopName property. This property is only used locally, and only if the interactive user is the same user who set up the consumer.

Starting with Windows Vista, the process running the CommandLineEventConsumer instance is started under the LocalSystem account and is in session 0. Services which run in session 0 cannot interact with user sessions.

Code
# Value of RunInteractively for each instance
$cimParameters = @{
    ClassName = 'CommandLineEventConsumer'
    Namespace = 'root/subscription'
    Property  = @('Name', 'RunInteractively')
}
Get-CimInstance @cimParameters |
    Select-Object -Property Name, RunInteractively
ShowWindowCommanduint32read

Window show state. It can be any of the values that can be specified in the *nCmdShow* parameter for the ShowWindow function.

Code
# Value of ShowWindowCommand for each instance
$cimParameters = @{
    ClassName = 'CommandLineEventConsumer'
    Namespace = 'root/subscription'
    Property  = @('Name', 'ShowWindowCommand')
}
Get-CimInstance @cimParameters |
    Select-Object -Property Name, ShowWindowCommand
UseDefaultErrorModebooleanread

If True, the default error mode is used.

Code
# Value of UseDefaultErrorMode for each instance
$cimParameters = @{
    ClassName = 'CommandLineEventConsumer'
    Namespace = 'root/subscription'
    Property  = @('Name', 'UseDefaultErrorMode')
}
Get-CimInstance @cimParameters |
    Select-Object -Property Name, UseDefaultErrorMode
WindowTitlestringread

Title that appears on the title bar of the process. This property is ignored for GUI applications.

Code
# Value of WindowTitle for each instance
$cimParameters = @{
    ClassName = 'CommandLineEventConsumer'
    Namespace = 'root/subscription'
    Property  = @('Name', 'WindowTitle')
}
Get-CimInstance @cimParameters |
    Select-Object -Property Name, WindowTitle
WorkingDirectorystringread

Working directory for this process.

Code
# Value of WorkingDirectory for each instance
$cimParameters = @{
    ClassName = 'CommandLineEventConsumer'
    Namespace = 'root/subscription'
    Property  = @('Name', 'WorkingDirectory')
}
Get-CimInstance @cimParameters |
    Select-Object -Property Name, WorkingDirectory
XCoordinateuint32read

X-offset, in pixels, from the left edge of the screen to the left edge of the window, if a new window is created.

Code
# Value of XCoordinate for each instance
$cimParameters = @{
    ClassName = 'CommandLineEventConsumer'
    Namespace = 'root/subscription'
    Property  = @('Name', 'XCoordinate')
}
Get-CimInstance @cimParameters |
    Select-Object -Property Name, XCoordinate
XNumCharactersuint32read

Screen buffer width, in character columns, if a new console window is created. This property is ignored in a GUI process.

Code
# Value of XNumCharacters for each instance
$cimParameters = @{
    ClassName = 'CommandLineEventConsumer'
    Namespace = 'root/subscription'
    Property  = @('Name', 'XNumCharacters')
}
Get-CimInstance @cimParameters |
    Select-Object -Property Name, XNumCharacters
XSizeuint32read

Width, in pixels, of a new window, if a new window is created.

Code
# Value of XSize for each instance
$cimParameters = @{
    ClassName = 'CommandLineEventConsumer'
    Namespace = 'root/subscription'
    Property  = @('Name', 'XSize')
}
Get-CimInstance @cimParameters |
    Select-Object -Property Name, XSize
YCoordinateuint32read

Y-offset, in pixels, from the top edge of the screen to the top edge of the window, if a new window is created.

Code
# Value of YCoordinate for each instance
$cimParameters = @{
    ClassName = 'CommandLineEventConsumer'
    Namespace = 'root/subscription'
    Property  = @('Name', 'YCoordinate')
}
Get-CimInstance @cimParameters |
    Select-Object -Property Name, YCoordinate
YNumCharactersuint32read

Screen buffer height, in character rows, if a new console window is created. This property is ignored in a GUI process.

Code
# Value of YNumCharacters for each instance
$cimParameters = @{
    ClassName = 'CommandLineEventConsumer'
    Namespace = 'root/subscription'
    Property  = @('Name', 'YNumCharacters')
}
Get-CimInstance @cimParameters |
    Select-Object -Property Name, YNumCharacters
YSizeuint32read

Height, in pixels, of the new window, if a new window is created.

Code
# Value of YSize for each instance
$cimParameters = @{
    ClassName = 'CommandLineEventConsumer'
    Namespace = 'root/subscription'
    Property  = @('Name', 'YSize')
}
Get-CimInstance @cimParameters |
    Select-Object -Property Name, YSize

Remarks

The CommandLineEventConsumer class is derived from the __EventConsumer abstract class.

The CreateSeparateWowVdm property indicates whether or not the new process runs in a private Virtual DOS Machine (VDM). The advantage of running separately is that a crash only terminates the single VDM. Programs running in distinct VDMs continue to function normally, and the 16-bit Windows-based applications running in separate VDMs have separate input queues. This means that if one application stops responding momentarily, the applications in separate VDMs continue to receive input. The disadvantage of running separately is that it takes significantly more memory to do so. You should set this property to True only if the user requests that 16-bit Windows-based applications run in their own VDM.

Note: The CommandLineEventConsumer uses the CreateProcess method internally, and passes the ExecutablePath and CommandLineTemplate properties as the *lpApplicationName* and *lpCommandLine* parameters. The following Managed Object Format (MOF) code example does not use CommandLineEventConsumer correctly.

```mof

instance of CommandLineEventConsumer

{

ExecutablePath = "C:\\windows\\system32\\cscript.exe";

CommandLineTemplate = "C:\\scripts\\MyScript.js param1 param2";

};

```

The CreateProcess method passes *lpCommandLine* as argv[0], argv[1], and so on. Because argv[0] for 16-bit applications used to be reserved for the executable file name, the previous MOF code results in the process being created as though the following command is entered at the command prompt: c:\windows\system32\cscript.exe param1 param2.

The previous command does not succeed because Cscript.exe does not look at argv[0], and so it does not recognize that it does not contain its own name, but something else ("c:\\scripts\\MyScript.js"). The following example identifies the recommended use of CommandLineEventConsumer.

```mof

instance of CommandLineEventConsumer

{

ExecutablePath = "C:\\windows\\system32\\cscript.exe";

CommandLineTemplate = "C:\\windows\\system32\\cscript.exe"

"C:\\scripts\\MyScript.js param1 param2";

};

```

The previous use of CommandLineEventConsumer results in the process created as though the following command was entered at the command prompt: c:\windows\system32\cscript.exe c:\scripts\MyScript.js param1 param2

Because "c:\\scripts\\MyScript.js" is now argv[1], it is seen by Cscript.exe and the command succeeds.

For more information, see the CreateProcess function.

Inheritance

Superclass chain

  1. __SystemClass
  2. __IndicationRelated
  3. __EventConsumer
  4. CommandLineEventConsumer

Known subclasses

No known subclass.

Requirements

Namespace
root/subscription
Minimum client
Windows Vista
Minimum server
Windows Server 2008
MOF file
Wbemcons.mof
DLL
Wbemcons.dll
Class qualifiers

AMENDMENT

Microsoft source

Source: Microsoft Learn

Descriptions, properties and methods come from the Microsoft documentation (MicrosoftDocs/win32 repository), published under the CC BY 4.0 licence. Formatting and translations are specific to this site; the PowerShell examples are written for it.