Getting names of enumerated processes

Started by
11 comments, last by SelethD 13 years, 11 months ago
I have googled and searched on these forums all day, and I can not seem to find a simple example of how to ...

1. Enumerate all the processes running
2. Get the names of these processes

I am using VC++ in vis studio 2008 , running on Win Vista.

This is what I have found so far...

Enumerating the processes seems to work ok, however when getting the names, one example said use 'EnumProcessModules' then you use 'GetModuleBaseName' to get the name of the first module in the process (should be the .exe name)
This looks like a good way, however, I cant get the 'EnumProcessModules' to work, I keep getting a ''EnumProcessModules': identifier not found' error.

So then another way said use 'GetProcessImageFileName' however, then documentation when i looked it up, said this is really not a very good method to use. I also got an 'identifier not found' with it also.

So if anyone knows the correct way to do this, also if anyone can tell me what exactly I need to do to not get the 'identifier not found' errors, your help is muchly appreciated.

Thanks

[Edited by - SelethD on June 18, 2010 1:04:51 PM]
Advertisement
Have you #included psapi.h?

Also, Visual Studio 2007 is not an actual product :D

Niko Suni

yeah, this is what I have included...

#pragma once

#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
// Windows Header Files:
#include <winsock2.h>
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include <psapi.h>
WIN32_LEAN_AND_MEAN causes some headers to omit a lot of functions. Try to comment it out.

Also see this.

Niko Suni

Ugh! This is so frustrating.

The link you provided says it uses psapi.h, I have included it. I even right-clicked on the #include <psapi.h> and did open file, and I looked, and found the EnumProcessModules declaration.
And I removed the 'WIN32_LEAN_AND_MEAN' and still... still... I get

error C3861: 'EnumProcessModules': identifier not found

There must be SOMETHING im missing, or not doing... hmmm. Im stuck :P
GetProcessImageFileName
GetModuleFileNameEx
GetModuleFileName

Process Enumeration
Process Status API
Tool Help Library
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
@LessBread

I read about those functions, and I understand them, but I keep getting the

error C3861: 'EnumProcessModules': identifier not found
First off, which version of MSVC are you actually using? As mentioned, 2007 is not a valid version number. Secondly, if you create a brand new project and try using the source code from one of the PSAPI examples, does it compile? Ex: Enumerating All Modules For a Process.
Ooops, sorry, that was a typo, its VS 2008 express edition.

I started a brand new project, and did a straight copy paste of the example, and now im getting a link error

1>test.obj : error LNK2019: unresolved external symbol _GetModuleBaseNameW@16 referenced in function "int __cdecl GetProcessName(unsigned long,wchar_t *)" (?GetProcessName@@YAHKPA_W@Z)

So I would assume im missing a library? For the life of me I cant remeber how to link a .lib or whatever this needs.

Thanks
Go to your project's settings, find the linker section and under input there should be a line for additional dependencies. Add psapi.lib to that line.

This topic is closed to new replies.

Advertisement