#include <Windows.h>
#include <TlHelp32.h>
#include <stdio.h>
int main()
{
PROCESSENTRY32 processEntry = { 0 };
processEntry.dwSize = sizeof (PROCESSENTRY32);
HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
if (hProcessSnap == INVALID_HANDLE_VALUE) return -1;
BOOL bRet = Process32First(hProcessSnap,&processEntry);
while (bRet)
{
int nLength = WideCharToMultiByte(CP_ACP, 0, processEntry.szExeFile, -1, NULL, 0, NULL, NULL); //获取字符长度
char *str = ( char *) malloc ( sizeof ( char )*nLength);
WideCharToMultiByte(CP_ACP, 0, processEntry.szExeFile, -1, str, nLength, NULL, NULL); //编码转换-unicode转ansi
printf ( "ProcessID:%d %s\n" ,processEntry.th32ProcessID,str);
bRet = Process32Next(hProcessSnap,&processEntry);
}
CloseHandle(hProcessSnap);
system ( "pause" );
return 0;
}
|