- Finding the process ID
- Task Manager
- The tasklist command
- TList utility
- The .tlist debugger command
- PowerShell Get-Process command
- CSRSS and user-mode drivers
- Find process by name
- How to get the process name in C++
- 6 Answers 6
- Not the answer you’re looking for? Browse other questions tagged c++ windows winapi or ask your own question.
- Linked
- Related
- Hot Network Questions
- Subscribe to RSS
- Finding out Windows service’s running process name .NET 1.1
- 6 Answers 6
- How to Identify the Process that has Locked a File in Windows
- Find which process has locked a file using:
- 1. Resource Monitor
- 2. Process Explorer
- 3. Handle from Windows Sysinternals
- Sysinternals Handle: Command-line arguments
- Add Sysinternals Handle to right-click menu
- 4. OpenFiles.exe — a built-in console tool
- Enable “Maintain Objects List” global flag for the First time
- View open files and the corresponding process names
- Disconnect files opened remotely from shared folder.
- 5. OpenedFilesView
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.
Find process by name
Не получается получить id процесса в C++.
возвращает -1 при pProcessName = «notepad.exe»
Добавлено через 33 секунды
мне нужно именно через имя процесса, а не имя окна
Как взять title, process, process id активного окна?
Хочу в этом switch, отловить title, process, process id. У меня есть 2 функции LRESULT CALLBACK.
The process cannot access the file because it is being used by another process
Здравствуйте, столкнулся с проблемой. При компиляции кода в MSVS 12 выдаётся следующая ошибка.
измените на многобайтовую кодировку
Добавлено через 35 секунд
закройте тему
Заказываю контрольные, курсовые, дипломные и любые другие студенческие работы здесь или здесь.
Почему map.find не доработают для std::find
Добрый вечер, вопрос философский о разработчиках стандарта и последующих имплементациях.
Salsa20 File Encryption: The process cannot access the file because it is being used by another process
Использую алгоритм Сальса20, вот мой код: using (var salsa = new Salsa20.Salsa20()) .
Отличие find -name от find -path
Собственно, вопрос в названии темы. Подскажите, пожалуйста. Читаю man, но понять никак не могу.
How to get the process name in C++
How do I get the process name from a PID using C++ in Windows?
6 Answers 6
I guess the OpenProcess function should help, given that your process possesses the necessary rights. Once you obtain a handle to the process, you can use the GetModuleFileNameEx function to obtain full path (path to the .exe file) of the process.
You can obtain the process name by using the WIN32 API GetModuleBaseName after having the process handle. You can get the process handle by using OpenProcess.
To get the executable name you can also use GetProcessImageFileName.
All the above methods require psapi.dll to be loaded (Read the remarks section) and iterating through process snapshot is an option one should not even consider for getting a name of the executable file from an efficiency standpoint.
The best approach, even according to MSDN recommendation, is to use QueryFullProcessImageName.
If you are trying to get the executable image name of a given process, take a look at GetModuleFileName.
Check out the enumprocess functions in the tool help library:
Try this function :
Not the answer you’re looking for? Browse other questions tagged c++ windows winapi or ask your own question.
Linked
Related
Hot Network Questions
Subscribe to RSS
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.4.16.39093
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.
Finding out Windows service’s running process name .NET 1.1
We are using a badly written windows service, which will hang when we are trying to Stop it from code. So we need to find which process is related to that service and kill it. Any suggestions?
6 Answers 6
WMI has this information: the Win32_Service class.
A WQL query like
using System.Management should do the trick.
From a quick look see: taskllist.exe /svc and other tools from the command line.
You can use System.Management.MangementObjectSearcher to get the process ID of a service and System.Diagnostics.Process to get the corresponding Process instance and kill it.
The KillService() method in the following program shows how to do this:
25ms using this solution: stackoverflow.com/questions/1574019/… – SharpC Jun 7 ’19 at 10:43
To find the process name and id, and also if the same process hosts other services.
To answer exactly to my question — how to find Process related to some service:
1s, whereas for this solution about
Microsoft/SysInternals has a command-line tool called PsKill that allows you to kill a process by name. This tool also allows you to kill processes on other servers. Windows SysInternals
Usage: pskill [-t] [\computer [-u username [-p password]]]
-t Kill the process and its descendants.
-u Specifies optional user name for login to remote computer.
-p Specifies optional password for user name. If you omit this you will be prompted to enter a hidden password.
I guess it’s a two step process — if it’s always the same service, you can easily find the process name using methods suggested in other answers.
I then have the following code in a class on a .NET 1.1 web server:
The Kill method can throw a few exceptions that you should consider catching — especially the Win32Exception, that is thrown if the process cannot be killed.
Note that the WaitForExit method and HasExited property also exist in the 1.1 world, but aren’t mentioned on the documentation page for Kill in 1.1.
How to Identify the Process that has Locked a File in Windows
When you attempt to delete a file or folder which is in use by a process, the File In Use dialog appears showing the name of the program that has locked the file.
However, there are cases where the “File In Use” dialog doesn’t show the name of the process that has a lock on the file you’re trying to delete. In some cases, the dialog will show “the action can’t be completed because the file is open in another process“.
For investigating processes and locked files, Windows Sysinternals Process Explorer is probably the first option that comes to mind for most users. However, there are two built-in solutions to display the current open files list along with corresponding process names.
Find which process has locked a file using:
1. Resource Monitor
Resource Monitor (resmon.exe) is a built-in tool that has many useful features. With Resource Monitor, you can track current network and internet usage, view associated handles for locked files, as well as manage processes just as you’d using the Task Manager.
To find the process name that has a file locked, click the CPU tab, type the file name or part of it in the Associated Handles text box.
2. Process Explorer
Process Explorer needs no introduction. In Process Explorer, all you need to do is use the Find feature and type in the file name. This shows the process that’s accessing the file.
From the lower pane view, you can close the file handle if necessary.
You must run Process Explorer as administrator in order to manage processes which are running elevated. To elevate Process Explorer, click the File menu → Show Details for All Processes.
3. Handle from Windows Sysinternals
Handle is a utility from Microsoft Sysinternals that displays information about open handles for any process in the system. You can use it to see the programs that have a file open, or to see the object types and names of all the handles of a program. Handle is like a command-line version of Process Explorer.
Note: Handle v4.21 has a small bug where it always reports “No matching handles found” if the drive-letter is in uppercase. Hope Microsoft fixes it in the next update.
From an admin Command Prompt window, use the command-line syntax to find the process which is having the file open:
If the file name contains spaces, enclose it within double quotes.
Example:
(Mentioning the filename without the path may not necessarily work in every situation. It’s advisable to include the full path always.)
The output shows the process name, the process identifier, user name, the locked (target) file name with path.
Sysinternals Handle: Command-line arguments
-a | Dump all handle information. |
-l | Just show pagefile-backed section handles. |
-c | Closes the specified handle (interpreted as a hexadecimal number). You must specify the process by its PID.WARNING: Closing handles can cause application or system instability. |
-y | Don’t prompt for close handle confirmation. |
-s | Print count of each type of handle open. |
-u | Show the owning user name when searching for handles. |
-p | Dump handles belonging to process (partial name accepted). |
name | Search for handles to objects with (fragment accepted). |
-nobanner | Do not display the startup banner and copyright message. |
No arguments will dump all file references.
Add Sysinternals Handle to right-click menu
You can add Sysinternals Handle to the right-click menu for files to quickly find the program that has locked the file. To add it to the context menu, follow these steps:
- Download Handle from Microsoft Sysinternals site.
- Copy the files handle.exe & handle64.exe to a folder – e.g., d:\tools
- Copy the following lines of code to Notepad, and save the file as find_handle.vbs to a permanent location.
Note: The Sysinternals Handle.exe path is hard-coded as d:\tools\handle.exe in the above script. If the program is located on a different path, modify the path in the script accordingly. For 64-bit Windows, you can use either handle.exe or handle64.exe
To remove the Find Handle context menu entry, start the Registry Editor ( regedit.exe ) and delete the following key:
4. OpenFiles.exe — a built-in console tool
Another built-in tool we’re going to use is Openfiles.exe, a console tool that’s not new to Windows. It was originally introduced in 2000 as part of the Windows Resource Kit 2000/2003 tools. This utility was then included by default in Windows Vista and higher (including Windows 10). Openfiles displays the currently open files list from local or shared folders, along with the Handle ID and Process executable name. This tool also allows you to disconnect one or more files that are opened remotely from a shared folder.
Enable “Maintain Objects List” global flag for the First time
First, to enable tracking of local file handles, you need to turn on ‘maintain objects list’ flag by running the following command from admin Command Prompt.
You’ll see the following message:
INFO: The system global flag ‘maintain objects list’ is currently enabled.
You’ll need to run this command for the first time only. Then restart Windows for the change to take effect.
View open files and the corresponding process names
After restarting Windows, from an admin Command Prompt window, type:
This lists the File/Handle ID, Process Name and the list of files opened locally or opened remotely via local share points, in a table format.
To view the output in List or CSV formats, use the /query parameter.
To copy the output to clipboard, pipe the output to Clip.exe as below. Then paste the output in Notepad or any other editor of your choice.
For more information on copying Command Prompt output to clipboard or save the output to a file, check out the article How to Copy Command Prompt Output Text to Clipboard or Save to File?
To find if a particular file is being in use by a program (and to know which program), you may use the following command-line.
The above command lists all open files that contain the word “eiffel” in the file name. In this example, Word 2016 is currently having the lock over the file “The Eiffel Tower.docx” (ID 4576).
And “File In Use” dialog tells me the same thing.
Disconnect files opened remotely from shared folder.
To disconnect files opened from shared folder so that you can delete, rename the file or modify the contents, use the /disconnect parameter to cut connections to that file. Here are the command-line options.
Openfiles.exe perfectly does the job of listing all open files along with the process names, but it can’t forcibly kill processes. However, this excellent (but overlooked) built-in console tool can come in handy when you want to quickly find a process name that’s using a file, or to disconnect a file that’s being accessed through a shared folder by a network user — without depending on a third-party solution.
5. OpenedFilesView
OpenedFilesView from Nirsoft displays the list of all opened files on your system. For each opened file, additional information is displayed: handle value, read/write/delete access, file position, the process that opened the file, and more… Optionally, you can also close one or more opened files, or close the process that opened these files.