Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I get the name of a process by its pid? 1

Status
Not open for further replies.

AliFessi

Programmer
Jul 3, 2001
12
DE
Hi,

My name is Ali. I am writing a dll with Visual C++ (it 's not an MFC' dll). I want to recognize which process is using the dll. With _getpid () I could get the process id. And now, how can I get the name of the process?!

Thanks !
 
The API function GetStartupInfo retrieves data about the curent process in a LPSTARTUPINFO structure. One of its member lpTitle is the main window caption/process name.

VOID GetStartupInfo(
LPSTARTUPINFO lpStartupInfo // startup information
);

Hope this helps, s-)

Blessed is he who in the name of justice and good will, shepards the week through the valley of darknees...
 
There are no easy ways to do it, if You need name of another Process (with ID != GetCurrentProcessId()). You must enum all Processes in System and compare founded IDs with Your ID. For that You need:
1) Windows 95/98/2000 - use CreateToolhelp32Snapshot() and another Functions of this Group (search help of Visual Studio for source sample).
2)Windows NT- use Functions of PSAPI.DLL (EnumProcesses() and it's callback - You can find source in search.microsoft.com).

Regards.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top