#include <stdio.h>
#include <windows.h>
#include "PSAPI.H"
#pragma comment( lib, "PSAPI.LIB" )
int main(void)
{
DWORD processid[1024],needed,processcount,i
HANDLE hProcess
HMODULE hModule
char path[MAX_PATH] = ""
char temp[256]
printf("ShowProcessPath with [Process Status API]/n")
EnumProcesses(processid, sizeof(processid), &needed)
processcount=needed/sizeof(DWORD)
for (i=0i<processcounti++)
{
hProcess=OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,false,processid[i])
if (hProcess)
{
EnumProcessModules(hProcess, &hModule, sizeof(hModule), &needed)
GetModuleFileNameEx(hProcess, hModule, path, sizeof(path))
GetShortPathName(path,path,256)
itoa(processid[i],temp,10)
printf("%s --- %s/n",path,temp)
}
else
{
printf("Failed!!!/n")
}
}
CloseHandle(hProcess)
CloseHandle(hModule)
itoa(processcount,temp,10)
printf("/nProcess Count:%s/n/n"余宽,temp)
return 0
}
利用windows API获得:
CString GetAppPath() {CStringstrAppPath // 保存结果
TCHAR szModuleFileName[MAX_PATH] // 全路径名
TCHAR drive[_MAX_DRIVE] // 盘符名称,比如说C盘啊,D盘啊
TCHAR dir[_MAX_DIR] // 目录
TCHAR fname[_MAX_FNAME] // 进程名字
TCHAR ext[_MAX_EXT] //后缀,一般为exe或者是dll
if (NULL == GetModuleFileName(NULL, szModuleFileName, MAX_PATH)) //获得当前进程码毕的文件路凳罩径
return FALSE
_tsplitpath_s( szModuleFileName, drive, dir, fname, ext ) 枣模闹//分割该路径,得到盘符,目录,文件名,后缀名
strAppPath = drive
strAppPath += dir
return strAppPath
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)