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, CreateNewConsoleExamples
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, CreateNewConsoleThe 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, FlagsProperties
| Name | Type | Access | Description | |||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| CommandLineTemplate# | string | read | 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 | |||||||||||||||||||||||||||
| CreateNewConsole# | boolean | read | Not used. If a value is assigned to this property, a tracing message is generated. For more information, see Tracing WMI Activity. Code | |||||||||||||||||||||||||||
| CreateNewProcessGroup# | boolean | read | 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 | |||||||||||||||||||||||||||
| CreateSeparateWowVdm# | boolean | read | 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 | |||||||||||||||||||||||||||
| CreateSharedWowVdm# | boolean | read | 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 | |||||||||||||||||||||||||||
| CreatorSID# | uint8[] | 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 | |||||||||||||||||||||||||||
| DesktopName# | string | read | Not used. If a value is assigned to this property a tracing message is generated. For more information, see Tracing WMI Activity. Code | |||||||||||||||||||||||||||
| ExecutablePath# | string | read | 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 | |||||||||||||||||||||||||||
| FillAttribute# | uint32 | read | Specifies the initial text and background colors if a new console window is created in a console application Code | |||||||||||||||||||||||||||
| FillAttributes# | uint32 | read/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)
CodeWarning. Changes the system: check with -WhatIf first. An elevated console is often required. | |||||||||||||||||||||||||||
| ForceOffFeedback# | boolean | read | If True, the feedback cursor is forced off while the process is starting. The normal cursor is displayed. Code | |||||||||||||||||||||||||||
| ForceOnFeedback# | boolean | read | 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 | |||||||||||||||||||||||||||
| KillTimeout# | uint32 | read | 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 | |||||||||||||||||||||||||||
| MachineName# | string | read | Name of the computer to which Windows Management Instrumentation (WMI) sends events. Code | |||||||||||||||||||||||||||
| MaximumQueueSize# | uint32 | read | Maximum queue for a specific consumer, in bytes. Code | |||||||||||||||||||||||||||
| Name# key | string | read | Unique name of a consumer. Code | |||||||||||||||||||||||||||
| Priority# | sint32 | read | Scheduling priority level of the process threads. The following list lists the priority levels available. Values (4)
Code | |||||||||||||||||||||||||||
| RunInteractively# | boolean | read | 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 | |||||||||||||||||||||||||||
| ShowWindowCommand# | uint32 | read | Window show state. It can be any of the values that can be specified in the *nCmdShow* parameter for the ShowWindow function. Code | |||||||||||||||||||||||||||
| UseDefaultErrorMode# | boolean | read | If True, the default error mode is used. Code | |||||||||||||||||||||||||||
| WindowTitle# | string | read | Title that appears on the title bar of the process. This property is ignored for GUI applications. Code | |||||||||||||||||||||||||||
| WorkingDirectory# | string | read | Working directory for this process. Code | |||||||||||||||||||||||||||
| XCoordinate# | uint32 | read | 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 | |||||||||||||||||||||||||||
| XNumCharacters# | uint32 | read | Screen buffer width, in character columns, if a new console window is created. This property is ignored in a GUI process. Code | |||||||||||||||||||||||||||
| XSize# | uint32 | read | Width, in pixels, of a new window, if a new window is created. Code | |||||||||||||||||||||||||||
| YCoordinate# | uint32 | read | 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 | |||||||||||||||||||||||||||
| YNumCharacters# | uint32 | read | Screen buffer height, in character rows, if a new console window is created. This property is ignored in a GUI process. Code | |||||||||||||||||||||||||||
| YSize# | uint32 | read | Height, in pixels, of the new window, if a new window is created. Code |
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
- __SystemClass
- __IndicationRelated
- __EventConsumer
- 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
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.