You say "which programs", but your example seems to ask whether HWLONG does run notbad.exe.
On a different* operating system I could ask: pgrep -u HWLONG notbad
and answer would be "yes" if any pids are listed, while ps ax -u HWLONG
lists all processes of that user.
*Different OS is a key point. The C++ is OS agnostic. If you want to do something OS-specific, like get info about processes, then you have to use tha API of the OS to get that info. That is, not call functions from C++ Standard Library, but from the OS.
In other words, get a list of all running processes, then, for each process, open a handle to the process, open the process' access token (via its handle), and finally query the "user" from the process' access token. This allows you to filter the process list by user.
its probably the 'right' ^^ way to do it, but
system("tasklist /v >somefile.txt"); will dump a snapshot that will be a half second or so out of date if you want a quick fix.. easy to parse out the info from there. There may be a way to get it without an intermediate file, not sure. Or if you can pipe the output of that into your program with a batch file or whatever?
Is there a function in C PLUS Plus to know which programs are running on the other user?
Yes - as per kigar64551's post above. But if you can get the info you want from tasklist, why write a new program rather than just using tasklist (as part of a batch file if the tasklist params need to change)? if the output from tasklist isn't in a needed format, then more simply write a C++ program that takes as input the output from tasklist and produces the required output.