16,472
社区成员
发帖
与我相关
我的任务
分享
HANDLE hSnapShot = NULL;//进程映像
int iNum;
CString myCmd = (CString)CommandLineToArgvW((LPCWSTR)GetCommandLine(),&iNum)[0];//得到当前程序命令行的第一个参数
int iStart = 0;
int iEnd = 0;
while (iStart >= 0)
{
iEnd = iStart;
iStart = myCmd.Find(_T("\\"),iStart + 1);
}
if (myCmd.Find(_T("\\"), 0) <0) iEnd = -1;
myCmd = myCmd.Right(myCmd.GetLength() - iEnd - 1);// 实际运行文件名,不含路径
hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);//获取当前进程快照
PROCESSENTRY32 prosInfo;//定义PROCESSENTRY32结构
prosInfo.dwSize = sizeof(prosInfo);//设置PROCESSENTRY32结构大小
BOOL bStatus = Process32First(hSnapShot, &prosInfo);//获得第一个进程的句柄
while(bStatus)
{
CString strName = prosInfo.szExeFile;
CString strProcessID; // 进程ID
strProcessID.Format(_T("%d"), prosInfo.th32ProcessID);
bStatus = Process32Next(hSnapShot, &prosInfo);//下一个
}
CloseHandle(hSnapShot);//关闭快照