- Get full running process list ( Visual C++ )
- 4 Answers 4
- Getting a list of all open windows in c++ and storing them
- 2 Answers 2
- How do you list all processes on the command line in Windows?
- 15 Answers 15
- Get ALL open windows
- 3 Answers 3
- 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
Get full running process list ( Visual C++ )
I am currently using the EnumProcesses function to obtain a list of running processes. Since my application runs in user space, however, it is not able to get handles for processes not running under the user, including System processes. Is there another method that will give me access to these? All I need are the process names.
4 Answers 4
I finally found a solution (figures after posting here as my last desperate attempt). If anyone else only needs a list of process names running on the system (all processes), this will do it for you.
Just to add to this answer, I built this for cases when you are looking for just one particular process instead of the entire list.
I should note here this was written in Embarcadero RAD Studio (C++ Builder) and per @Remy_Lebeau System::AnsiString is a C++Builder string class for 8bit ANSI character data in its VCL/FMX frameworks.
If all you need are just process names, then use WTSEnumerateProcesses as such:
The benefit of using this method is that you don’t have to open each process individually and then retrieve its name as what you’d have to do if you went with EnumProcesses instead, which also won’t work if you try to open processes that run with higher privileges than your user account.
Additionally this method is also much faster than calling Process32First() / Process32Next() in a loop.
WTSEnumerateProcesses is a lesser known API that has been available since Windows XP.
Getting a list of all open windows in c++ and storing them
I’m currently trying to get a list of all opened windows and storing them inside a vector. I’ve been looking at the code so much that the solution could be very easy but I don’t seem to get it done without a global variable (which I want to avoid).
Here is the code:
I want to store all titles in the vector but I don’t know how as I can’t pass the vector into the function.
2 Answers 2
The second parameter (lParam) to EnumWindows is documented as:
An application-defined value to be passed to the callback function.
Just pass your container to the API call:
And use it in your callback:
- The code presented uses a std::wstring in place of std::string . This is necessary so that the entire character set can be represented.
- As written, the code isn’t correct. There are (invisible) code paths, that have no well-defined meaning. The Windows API is strictly exposed as a C interface. As such, it doesn’t understand C++ exceptions. Particularly with callbacks it is vital to never let C++ exceptions travel across unknown stack frames. To fix the code apply the following changes:
- [C++11 only] Mark the callback noexcept.
- Wrap the entire callback inside a try-catch block, and handle any exceptions appropriately.
- [C++11 only] With C++11 you can pass C++ exceptions across unknown stack frames, by passing a std::exception_ptr, and calling std::rethrow_exception at the call site.
How do you list all processes on the command line in Windows?
Is there a command equivalent to ‘ps’ on Unix that can list all processes on a Windows machine?
15 Answers 15
Working with cmd.exe:
(you can query remote machines as well with /node:ComputerOrIP , and there are a LOT more ways to customize this command: link)
You can call wmic process list to see all processes.
I wanted to mention that WMIC (pam’s entry) can do a lot more. Have a look at my WMIC snippets page, which is a cheatsheet showing many of the common ways to use WMIC (with sample output shown) here
WMIC /OUTPUT:C:\ProcessList.txt PROCESS get Caption,Commandline,Processid
I tried on Windows 7. The command is: TASKLIST /FI «IMAGENAME eq application_name»
Eg: c:\>TASKLIST /FI «IMAGENAME eq notepad.exe»
To show all process with port details:
Also to kill the process you can use c:\> pskill or tskill processname
Eg: c:\> tskill notepad
tasklist or pslist from sysinternals. Also, get-process is amazing from PowerShell.
If you use Powershell, it has the ‘ps’ command (it is aliased to Get-Process)
To kill a process use:
If you running windows XP try using the ‘tasklist’ command. I tried it out with Vista and it seems to also work.
Use this command to see all the processes in windows machine
tasklist /svc
open windows command prompt
I had following problem on Windows 2003 SP2: Tasklist didn’t return any output on stdout or stderr, when called from a process started as Windows service (even under Local Account). Tasklist returned with the (undocumented) code 128.
Called from the same program started as a normal process (not as service), it did run.
No help to change it. I couldn’t find any reason or solution but use «pslist /accepteula» of sysinternal instead of it.
Same problem with taskkill: I had to replace it whith pskill.
I have done a msproject ( c source code) , archive is available at : lsproc.zip project archive
this is a command line tool output:
Using WMI and Powershell you can do:
Then you can filter properties using Select-Object and show in GUI using Out-GridView .
Get ALL open windows
I am working on a WPF application and I need a way to get all the open windows within the application, including the ones that have been opened from another thread. I tried Application.Current.Windows but this does not give me the windows that have been opened from another thread. Is it even possible to access the windows opened by another thread? Shouldn’t all the windows be in the same Application Domain?
3 Answers 3
This should do it. It will return a list of integer pointers to each open window of the given application name:
Now as one of the commenter’s mentioned, you shouldn’t have multiple threads doing GUI work. One thread should be doing the GUI drawing while other threads do the actual other work.
The Window class checks that the current application’s dispatcher is the current thread’s dispatcher, if it is then it is added to the Windows collection. It doesn’t look like these other windows are exposed in a public collection but there is an internal property on Application , NonAppWindowsInternal that has the windows.
I would always create UI objects on a single UI thread. If you do so, you will have access to all the Window objects via Application.Current.Windows .
I’m unsure of this solution but it is what I found to be the closest to one.
Try getting the proceses:
If this doesn’t help, try using Process.GetProcessesByName(«ApplicationName») and see what it returns.
It may also help to look at this solution and the MSDN class page and the available methods in it.
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.