51200
#define EXTEND_SIZE 12800
#define REGKEY_PERF "software\\microsoft\\windows nt\\currentversion\\perflib"
#define REGSUBKEY_COUNTERS "Counters"
#define PROCESS_COUNTER "process"
#define PROCESSID_COUNTER "id process"
#define UNKNOWN_TASK "unknown"
#define MaxProcessNum 52//最大进程数量
#pragma comment(lib,"mpr.lib")
typedef struct ProcessInfo
{
char ProcessName[128];
DWORD dwProcessID;
}pi;
void banner();
int ConnIPC(char *,char *,char *);
DWORD GetProcessInfo(pi *,char *,char *,char *);
int main(int argc,char **argv)
{
int i,iRet;
pi TaskList[MaxProcessNum];
banner();
if(argc==1)
{
iRet=GetProcessInfo(TaskList,NULL,NULL,NULL);
printf("\nProcess Info for [LOCAL]:");
}
else if(argc==4)
{
iRet=GetProcessInfo(TaskList,argv,argv,argv);
printf("\nProcess Info for [%s]:",argv);
}
else
{
printf("\nUsage:%s <ip> <UserName> <Pass>",argv[0]);
return 1;
}
if(iRet>0)
for(i=0,printf("\nProcessName ProcessID");
i<iRet;
printf("\n%-20s %d",TaskList[i].ProcessName,TaskList[i].dwProcessID),i++);
return 0;
}
DWORD GetProcessInfo(pi *ProList,char *ip,char *user,char *pass)
{
DWORD rc,dwType,dwSize,i,dwProcessIdTitle,dwProcessIdCounter,dwRet=-1;
HKEY hKeyNames;
LPSTR buf = NULL,p,p2;
CHAR szSubKey[1024],szProcessName[MAX_PATH];
PPERF_DATA_BLOCK pPerf;
PPERF_OBJECT_TYPE pObj;
PPERF_INSTANCE_DEFINITION pInst;
PPERF_COUNTER_BLOCK pCounter;
PPERF_COUNTER_DEFINITION pCounterDef;
HKEY ghPerfKey =NULL, // get perf data from this key
ghMachineKey = NULL; // get title index from this key
BOOL bRemote=FALSE;
//
// Look for the list of counters. Always use the neutral
// English version, regardless of the local language. We
// are looking for some particular keys, and we are always
// going to do our looking in English. We are not going
// to show the user the counter names, so there is no need
// to go find the corresponding name in the local language.
//
__try
{
if((ip)&&(user)&&(pass))
{
if(ConnIPC(ip,user,pass)!=0)
{
printf("\nConnect to %s failed.",ip);
__leave;
}
&