网上比较多都是枚举进程获得进程名...
比较麻烦
所以查了下GetModuleFileNameEx的第2个参数NULL情况下获得进程名
// GetProcessNameByPID.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "windows.h"
#include "stdio.h"
#include "Psapi.h"
int main(int argc, char* argv[])
{
char buff[255];
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS,FALSE,3920); //3920为进程PID.由于测试我就直接塞个PID进去了
GetModuleFileNameEx(hProcess,NULL,buff,255);
printf("%s",buff);
return 0;
}
执行结果
D:/VCPRO/GetProcessNameByPID/Debug>GetProcessNameByPId.exe
C:/Documents and Settings/Sorawa/桌面/超级小软件.exe