Win32_Thread

Win32 Thread
root/cimv2dynamic

The Win32_Thread WMI class represents a thread of execution.

On this page

Main example

List instances

# All instances of Win32_Thread, with the main properties
Get-CimInstance -ClassName Win32_Thread |
    Select-Object -Property @(
        'CSName'
        'OSCreationClassName'
        'Name'
        'Caption'
        'Description'
        'Status'
        'InstallDate'
    )

Examples

Filter with WQL

# WQL filter evaluated by the provider: ExecutionState = 3 (Running)
Get-CimInstance -ClassName Win32_Thread -Filter 'ExecutionState = 3' |
    Select-Object -Property @(
        'CSName'
        'OSCreationClassName'
        'Name'
        'Caption'
        'Description'
        'Status'
        'InstallDate'
    )

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

Decode numeric values

# Lookup table for ExecutionState (values documented by Microsoft)
$executionStateName = @{
    0 = 'Unknown'
    1 = 'Other'
    2 = 'Ready'
    3 = 'Running'
    4 = 'Blocked'
    5 = 'Suspended Blocked'
    6 = 'Suspended Ready'
}
# Lookup table for ThreadState (values documented by Microsoft)
$threadStateName = @{
    0 = 'Initialized'
    1 = 'Ready'
    2 = 'Running'
    3 = 'Standby'
    4 = 'Terminated'
    5 = 'Waiting'
    6 = 'Transition'
    7 = 'Unknown'
}

Get-CimInstance -ClassName Win32_Thread |
    Select-Object -Property @(
        'CSName'
        'OSCreationClassName'
        'Name'
        'Caption'
        'Description'
        'Status'
        'InstallDate'
    )

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 {
    Get-CimInstance -CimSession $cimSession -ClassName Win32_Thread |
        Select-Object -Property @(
            'CSName'
            'OSCreationClassName'
            'Name'
            'Caption'
            'Description'
            'Status'
            'InstallDate'
        )
} 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 Win32_Thread
$cimClass.CimClassProperties |
    Select-Object -Property Name, CimType, Flags

Properties

22 of 22 properties
NameTypeAccessDescription
Captionstringread

Short description of the object.

Code
# Value of Caption for each instance
Get-CimInstance -ClassName Win32_Thread -Property CSName, OSCreationClassName, Caption |
    Select-Object -Property CSName, OSCreationClassName, Caption
CreationClassName keystringread

Name of the first concrete class to appear in the inheritance chain used in the creation of an instance. When used with the other key properties of the class, this property allows all instances of this class and its subclasses to be uniquely identified.

Code
# Value of CreationClassName for each instance
Get-CimInstance -ClassName Win32_Thread -Property CSName, OSCreationClassName, CreationClassName |
    Select-Object -Property CSName, OSCreationClassName, CreationClassName
CSCreationClassName keystringread

Creation class name of the scoping computer system.

Code
# Value of CSCreationClassName for each instance
Get-CimInstance -ClassName Win32_Thread -Property CSName, OSCreationClassName, CSCreationClassName |
    Select-Object -Property CSName, OSCreationClassName, CSCreationClassName
CSName keystringread

Name of the scoping computer system.

Code
# Value of CSName for each instance
Get-CimInstance -ClassName Win32_Thread -Property OSCreationClassName, CSName |
    Select-Object -Property OSCreationClassName, CSName
Descriptionstringread

Description of the object.

Code
# Value of Description for each instance
Get-CimInstance -ClassName Win32_Thread -Property CSName, OSCreationClassName, Description |
    Select-Object -Property CSName, OSCreationClassName, Description
ElapsedTimeuint64read

Total execution time, in milliseconds, given to this thread since its creation.

For more information about using uint64 values in scripts, see Scripting in WMI.

Unit: milliseconds

Code
# Value of ElapsedTime for each instance
Get-CimInstance -ClassName Win32_Thread -Property CSName, OSCreationClassName, ElapsedTime |
    Select-Object -Property CSName, OSCreationClassName, ElapsedTime
ExecutionStateuint16read

Current operating condition of the thread.

Values (7)
ValueLabelDescription
0Unknown
1Other
2Ready
3Running
4Blocked
5Suspended Blocked
6Suspended Ready
Code
# Value of ExecutionState for each instance
# Lookup table for ExecutionState (values documented by Microsoft)
$executionStateName = @{
    0 = 'Unknown'
    1 = 'Other'
    2 = 'Ready'
    3 = 'Running'
    4 = 'Blocked'
    5 = 'Suspended Blocked'
    6 = 'Suspended Ready'
}
Get-CimInstance -ClassName Win32_Thread -Property CSName, OSCreationClassName, ExecutionState |
    Select-Object -Property @(
        'CSName'
        'OSCreationClassName'
        @{ Name = 'ExecutionState'; Expression = { $executionStateName[[int]$_.ExecutionState] } }
    )
Handlestringread

Handle to a thread. The handle has full access rights by default. With the correct security access, the handle can be used in any function that accepts a thread handle. Depending on the inheritance flag specified when it is created, this handle can be inherited by child processes.

Code
# Value of Handle for each instance
Get-CimInstance -ClassName Win32_Thread -Property CSName, OSCreationClassName, Handle |
    Select-Object -Property CSName, OSCreationClassName, Handle
InstallDatedatetimeread

Object was installed. This property does not need a value to indicate that the object is installed.

Code
# Value of InstallDate for each instance
# CIM cmdlets already return a DateTime object: no conversion is needed
Get-CimInstance -ClassName Win32_Thread -Property CSName, OSCreationClassName, InstallDate |
    Select-Object -Property CSName, OSCreationClassName, InstallDate
KernelModeTimeuint64read

Time in kernel mode, in 100 nanosecond units. If this information is not available, a value of 0 (zero) should be used.

For more information about using uint64 values in scripts, see Scripting in WMI.

Unit: 100 nanoseconds

Code
# Value of KernelModeTime for each instance
Get-CimInstance -ClassName Win32_Thread -Property CSName, OSCreationClassName, KernelModeTime |
    Select-Object -Property CSName, OSCreationClassName, KernelModeTime
Namestringread

Label by which the object is known. When subclassed, the property can be overridden to be a key property.

Code
# Value of Name for each instance
Get-CimInstance -ClassName Win32_Thread -Property CSName, OSCreationClassName, Name |
    Select-Object -Property CSName, OSCreationClassName, Name
OSCreationClassName keystringread

Creation class name of the scoping operating system.

Code
# Value of OSCreationClassName for each instance
Get-CimInstance -ClassName Win32_Thread -Property CSName, OSCreationClassName |
    Select-Object -Property CSName, OSCreationClassName
OSName keystringread

Name of the scoping operating system.

Code
# Value of OSName for each instance
Get-CimInstance -ClassName Win32_Thread -Property CSName, OSCreationClassName, OSName |
    Select-Object -Property CSName, OSCreationClassName, OSName
Priorityuint32read

Dynamic priority of the thread. Each thread has a dynamic priority that the scheduler uses to determine which thread to execute. Initially, a thread's dynamic priority is the same as its base priority. The system can raise and lower the dynamic priority, to ensure that it is responsive (guaranteeing that no threads are starved for processor time). The system does not boost the priority of threads with a base priority level between 16 and 31. Only threads with a base priority between 0 and 15 receive dynamic priority boosts. Higher numbers indicate higher priorities.

Code
# Value of Priority for each instance
Get-CimInstance -ClassName Win32_Thread -Property CSName, OSCreationClassName, Priority |
    Select-Object -Property CSName, OSCreationClassName, Priority
PriorityBaseuint32read

Current base priority of a thread. The operating system may raise the thread's dynamic priority above the base priority if the thread is handling user input, or lower it toward the base priority if the thread becomes compute-bound. The PriorityBase property can have a value between 0 and 31.

Code
# Value of PriorityBase for each instance
Get-CimInstance -ClassName Win32_Thread -Property CSName, OSCreationClassName, PriorityBase |
    Select-Object -Property CSName, OSCreationClassName, PriorityBase
ProcessCreationClassName keystringread

Value of the scoping process CreationClassName property.

Code
# Value of ProcessCreationClassName for each instance
Get-CimInstance -ClassName Win32_Thread -Property CSName, OSCreationClassName, ProcessCreationClassName |
    Select-Object -Property CSName, OSCreationClassName, ProcessCreationClassName
ProcessHandlestringread

Process that created the thread. The contents of this property can be used by Windows application programming interface (API) elements.

Code
# Value of ProcessHandle for each instance
Get-CimInstance -ClassName Win32_Thread -Property CSName, OSCreationClassName, ProcessHandle |
    Select-Object -Property CSName, OSCreationClassName, ProcessHandle
StartAddressuint32read

Starting address of the thread. Because any application with appropriate access to the thread can change the thread's context, this value may only be an approximation of the thread's starting address.

Code
# Value of StartAddress for each instance
Get-CimInstance -ClassName Win32_Thread -Property CSName, OSCreationClassName, StartAddress |
    Select-Object -Property CSName, OSCreationClassName, StartAddress
Statusstringread

Current status of the object. Various operational and nonoperational statuses can be defined. Operational statuses include: "OK", "Degraded", and "Pred Fail" (an element, such as a SMART-enabled hard disk drive, may be functioning properly but predicting a failure in the near future). Nonoperational statuses include: "Error", "Starting", "Stopping", and "Service". The latter, "Service", could apply during mirror-resilvering of a disk, reload of a user permissions list, or other administrative work. Not all such work is online, yet the managed element is neither "OK" nor in one of the other states.

The values are:

Values (12)
ValueLabelDescription
OKOK
ErrorError
DegradedDegraded
UnknownUnknown
Pred FailPred Fail
StartingStarting
StoppingStopping
ServiceService
StressedStressed
NonRecoverNonRecover
No ContactNo Contact
Lost CommLost Comm
Code
# Value of Status for each instance
Get-CimInstance -ClassName Win32_Thread -Property CSName, OSCreationClassName, Status |
    Select-Object -Property CSName, OSCreationClassName, Status
ThreadStateuint32read

Current execution state for the thread.

Values (8)
ValueLabelDescription
0InitializedInitialized — It is recognized by the microkernel.
1ReadyReady — It is prepared to run on the next available processor.
2RunningRunning — It is executing.
3StandbyStandby — It is about to run, only one thread may be in this state at a time.
4TerminatedTerminated — It is finished executing.
5WaitingWaiting — It is not ready for the processor, when ready, it will be rescheduled.
6TransitionTransition — The thread is waiting for resources other than the processor,
7UnknownUnknown — The thread state is unknown.
Code
# Value of ThreadState for each instance
# Lookup table for ThreadState (values documented by Microsoft)
$threadStateName = @{
    0 = 'Initialized'
    1 = 'Ready'
    2 = 'Running'
    3 = 'Standby'
    4 = 'Terminated'
    5 = 'Waiting'
    6 = 'Transition'
    7 = 'Unknown'
}
Get-CimInstance -ClassName Win32_Thread -Property CSName, OSCreationClassName, ThreadState |
    Select-Object -Property @(
        'CSName'
        'OSCreationClassName'
        @{ Name = 'ThreadState'; Expression = { $threadStateName[[int]$_.ThreadState] } }
    )
ThreadWaitReasonuint32read

Reason why the thread is waiting. This value is only valid if the ThreadState member is set to Transition (6). Event pairs allow communication with protected subsystems.

Values (21)
ValueLabelDescription
0Executive
1FreePage
2PageIn
3PoolAllocation
4ExecutionDelay
5FreePage
6PageIn
7Executive
8FreePage
9PageIn
10PoolAllocation
11ExecutionDelay
12FreePage
13PageIn
14EventPairHigh
15EventPairLow
16LPCReceive
17LPCReply
18VirtualMemory
19PageOut
20Unknown
Code
# Value of ThreadWaitReason for each instance
# Lookup table for ThreadWaitReason (values documented by Microsoft)
$threadWaitReasonName = @{
    0 = 'Executive'
    1 = 'FreePage'
    2 = 'PageIn'
    3 = 'PoolAllocation'
    4 = 'ExecutionDelay'
    5 = 'FreePage'
    6 = 'PageIn'
    7 = 'Executive'
    8 = 'FreePage'
    9 = 'PageIn'
    10 = 'PoolAllocation'
    11 = 'ExecutionDelay'
    12 = 'FreePage'
    13 = 'PageIn'
    14 = 'EventPairHigh'
    15 = 'EventPairLow'
    16 = 'LPCReceive'
    17 = 'LPCReply'
    18 = 'VirtualMemory'
    19 = 'PageOut'
    20 = 'Unknown'
}
Get-CimInstance -ClassName Win32_Thread -Property CSName, OSCreationClassName, ThreadWaitReason |
    Select-Object -Property @(
        'CSName'
        'OSCreationClassName'
        @{ Name = 'ThreadWaitReason'; Expression = { $threadWaitReasonName[[int]$_.ThreadWaitReason] } }
    )
UserModeTimeuint64read

Time in user mode, in 100 nanoseconds units. If this information is not available, a value of 0 (zero) should be used.

For more information about using uint64 values in scripts, see Scripting in WMI.

Unit: 100 nanoseconds

Code
# Value of UserModeTime for each instance
Get-CimInstance -ClassName Win32_Thread -Property CSName, OSCreationClassName, UserModeTime |
    Select-Object -Property CSName, OSCreationClassName, UserModeTime

Remarks

The Win32_Thread class is derived from CIM_Thread.

Overview

For routine day-to-day monitoring, there is usually little reason to have a detailed list of threads and their associated properties. Computers create and delete thousands of threads during the course of a day, and few of these creations or deletions are meaningful to anyone but the developer who wrote the software.

However, when you are troubleshooting problems with an application, tracking the individual threads for a process allows you to identify when threads are created and when (or if) they are destroyed. Because threads that are created but not destroyed cause memory leaks, tracking individual threads can be useful information for support technicians. Likewise, identifying thread priorities can help pinpoint threads that, by running at an abnormally high priority, are preempting CPU cycles needed by other threads and other processes.

Using Win32_Thread

As implied in the preceding syntax block, the Win32_Thread class does not report the name of the process under which each thread runs. Instead, it reports the ID of the process under which the thread runs. To return the name of a process and a list of all its threads, your script must:

1. Connect to the Win32_Process class and return the list of processes and their process IDs.

2. Temporarily store this information in an array or Dictionary object.

3. For each process ID, return the list of threads for that process, and then display the process name and the list of threads.

Inheritance

Superclass chain

  1. CIM_ManagedSystemElement
  2. CIM_LogicalElement
  3. CIM_Thread
  4. Win32_Thread

Known subclasses

No known subclass.

Requirements

Namespace
root/cimv2
Minimum client
Windows Vista
Minimum server
Windows Server 2008
Provider
CIMWin32
MOF file
CIMWin32.mof
DLL
CIMWin32.dll
Class qualifiers

Dynamic Provider("CIMWin32") UUID("{8502C4DD-5FBB-11D2-AAC1-006008C78BC7}") 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.