- Finding the process ID
- Task Manager
- The tasklist command
- TList utility
- The .tlist debugger command
- PowerShell Get-Process command
- CSRSS and user-mode drivers
- GetProcessImageFileNameA function (psapi.h)
- Syntax
- Parameters
- Return value
- Remarks
- !process
- Parameters
- Additional Information
- Remarks
- Класс Win32_Process — работа с процессами
- Свойства класса Win32_Process
- Методы класса Win32_Process
Finding the process ID
Each process running in Windows is assigned a unique decimal number called the process ID (PID). This number is used in a number of ways, for example to specify the process when attaching a debugger to it.
This topic describes how you can determine the PID for a given app using Task Manager, the tasklist Windows command, the TList utility, or the debugger.
Task Manager
Task Manager can be opened in a number of ways, but the simplest is to select Ctrl+Alt+Delete, and then select Task Manager.
In Windows 10, first click More details to expand the information displayed. From the Processes tab, select the Details tab to see the process ID listed in the PID column.
Click on any column name to sort. You can right click a process name to see more options for a process.
Some kernel errors may cause delays in Task Manager’s graphical interface.
The tasklist command
Use the built in Windows tasklist command from a command prompt to display all processes, their PIDs, and a variety of other details.
Use tasklist /? to display command line help.
TList utility
Task List Viewer (TList), or tlist.exe, is a command-line utility that displays the list of tasks, or user-mode processes, currently running on the local computer. TList is included in the Debugging Tools for Windows. For information on how to download and install the debugging tools, see Download Debugging Tools for Windows.
If you installed the Windows Driver Kit in the default directory on a 64 bit PC, the debugging tools are located here:
C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\
When you run TList from the command prompt, it will display a list of all the user-mode processes in memory with a unique PID number. For each process, it shows the PID, process name, and, if the process has a window, the title of that window.
For more information, see TList.
The .tlist debugger command
If there’s already a user-mode debugger running on the system in question, the .tlist (List Process IDs) command will display a list of all PIDs on that system.
PowerShell Get-Process command
To work with automation scripts, use the Get-Process PowerShell command. Specify a specific process name, to see the process ID for that process.
For more information, see Get-Process.
CSRSS and user-mode drivers
To debug a user-mode driver running on another computer, debug the Client Server Run-Time Subsystem (CSRSS) process. For more information, see Debugging CSRSS.
GetProcessImageFileNameA function (psapi.h)
Retrieves the name of the executable file for the specified process.
Syntax
Parameters
A handle to the process. The handle must have the PROCESS_QUERY_INFORMATION or PROCESS_QUERY_LIMITED_INFORMATION access right. For more information, see Process Security and Access Rights.
Windows ServerВ 2003 and WindowsВ XP:В В The handle must have the PROCESS_QUERY_INFORMATION access right.
A pointer to a buffer that receives the full path to the executable file.
The size of the lpImageFileName buffer, in characters.
Return value
If the function succeeds, the return value specifies the length of the string copied to the buffer.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
Remarks
The file Psapi.dll is installed in the %windir%\System32 directory. If there is another copy of this DLL on your computer, it can lead to the following error when running applications on your system: «The procedure entry point GetProcessImageFileName could not be located in the dynamic link library PSAPI.DLL.» To work around this problem, locate any versions that are not in the %windir%\System32 directory and delete or rename them, then restart.
The GetProcessImageFileName function returns the path in device form, rather than drive letters. For example, the file name C:\Windows\System32\Ctype.nls would look as follows in device form:
To retrieve the module name of the current process, use the GetModuleFileName function with a NULL module handle. This is more efficient than calling the GetProcessImageFileName function with a handle to the current process.
To retrieve the name of the main executable module for a remote process in win32 path format, use the QueryFullProcessImageName function.
Starting with WindowsВ 7 and Windows ServerВ 2008В R2, Psapi.h establishes version numbers for the PSAPI functions. The PSAPI version number affects the name used to call the function and the library that a program must load.
If PSAPI_VERSION is 2 or greater, this function is defined as K32GetProcessImageFileName in Psapi.h and exported in Kernel32.lib and Kernel32.dll. If PSAPI_VERSION is 1, this function is defined as GetProcessImageFileName in Psapi.h and exported in Psapi.lib and Psapi.dll as a wrapper that calls K32GetProcessImageFileName.
Programs that must run on earlier versions of Windows as well as WindowsВ 7 and later versions should always call this function as GetProcessImageFileName. To ensure correct resolution of symbols, add Psapi.lib to the TARGETLIBS macro and compile the program with -DPSAPI_VERSION=1. To use run-time dynamic linking, load Psapi.dll.
The psapi.h header defines GetProcessImageFileName as an alias which automatically selects the ANSI or Unicode version of this function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions for Function Prototypes.
!process
The !process extension displays information about the specified process, or about all processes, including the EPROCESS block.
This extension can be used only during kernel-mode debugging.
Parameters
/s **** Session
Specifies the session that owns the desired process.
/m **** Module
Specifies the module that owns the desired process.
Process
Specifies the hexadecimal address or the process ID of the process on the target computer.
The value of Process determines whether the !process extension displays a process address or a process ID . If Process is omitted in any version of Windows, the debugger displays data only about the current system process. If Process is 0 and ImageName is omitted, the debugger displays information about all active processes. If -1 is specified for Process information about the current process is displayed.
Flags
Specifies the level of detail to display. Flags can be any combination of the following bits. If Flags is 0, only a minimal amount of information is displayed. The default varies according to the version of Windows and the value of Process. The default is 0x3 if Process is omitted or if Process is either 0 or -1; otherwise, the default is 0xF.
Bit 0 (0x1)
Displays time and priority statistics.
Bit 1 (0x2)
Displays a list of threads and events associated with the process, and their wait states.
Bit 2 (0x4)
Displays a list of threads associated with the process. If this is included without Bit 1 (0x2), each thread is displayed on a single line. If this is included along with Bit 1, each thread is displayed with a stack trace.
Bit 3 (0x8)
Displays the return address and the stack pointer for each function The display of function arguments is suppressed.
Bit 4 (0x10)
Sets the process context equal to the specified process for the duration of this command. This results in a more accurate display of thread stacks. Because this flag is equivalent to using .process /p /r for the specified process, any existing user-mode module list will be discarded. If Process is zero, the debugger displays all processes, and the process context is changed for each one. If you are only displaying a single process and its user-mode state has already been refreshed (for example, with .process /p /r), it is not necessary to use this flag. This flag is only effective when used with Bit 0 (0x1).
ImageName
Specifies the name of the process to be displayed. The debugger displays all processes whose executable image names match ImageName. The image name must match that in the EPROCESS block. In general, this is the executable name that was invoked to start the process, including the file extension (usually .exe), and truncated after the fifteenth character. There is no way to specify an image name that contains a space. When ImageName is specified, Process must be zero.
Additional Information
For information about processes in kernel mode, see Changing Contexts. For more information about analyzing processes and threads, see Microsoft Windows Internals, by Mark Russinovich and David Solomon.
Remarks
The following is an example of a !process 0 0 display:
The following table describes some of the elements of the !process 0 0 output.
Element | Meaning | ||
---|---|---|---|
Element | Meaning |
---|---|
WAIT | The parenthetical comment after this heading gives the reason for the wait. The command dt nt!_KWAIT_REASON will display a list of all wait reasons. |