枚举本地远程NT系统进程[4]

[入库:2005年9月19日] [更新:2007年3月24日]

本文简介:

if(iRet>0)

for(i=0,printf("\nProcessName ProcessID");


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;

 }

  else

 bRemote=TRUE;

 }

 //连接本地or远程注册表

 if(RegConnectRegistry(ip,HKEY_PERFORMANCE_DATA,

  &ghPerfKey)!=ERROR_SUCCESS)

 {

  printf("\nRegConnectRegistry() 1 failed:%d",GetLastError());

  __leave;

 }

` if(RegConnectRegistry(ip,HKEY_LOCAL_MACHINE,&ghMachineKey)!=ERROR_SUCCESS)

 {

  printf("\nRegConnectRegistry() 2 failed:%d",GetLastError());

  __leave;

 }



sprintf( szSubKey, "%s\\%03x", REGKEY_PERF,MAKELANGID( LANG_ENGLISH, SUBLANG_NEUTRAL));



if(RegOpenKeyEx(ghMachineKey,szSubKey,0,KEY_READ,&hKeyNames)!=ERROR_SUCCESS)

  __leave;



 // 从counter names取得需要的缓冲区大小

if(RegQueryValueEx(hKeyNames,REGSUBKEY_COUNTERS,NULL,&dwType,NULL,&dwSize)!= ERROR_SUCCESS)

__leave;

 //分配内存

 buf = (LPSTR) malloc( dwSize );

 if (buf == NULL)

  __leave;

 memset( buf, 0, dwSize );

 // read the counter names from the registry

if(RegQueryValueEx(ghPerfKey,REGSUBKEY_COUNTERS,NULL,&dwType,(LPBYTE) buf,&dwSize)!= ERROR_SUCCESS)

  __leave;

 // now loop thru the counter names looking for the following counters:

 //1. "Process"process name

 //2."ID Process"process id



 // the buffer contains multiple null terminated strings and then

 // finally null terminated at the end.the strings are in pairs of

 // counter number and counter name.



 p = buf;

 while (*p)

 {

 if (p>buf)

for( p2=p-2; isdigit(*p2); p2--) ;

 if (stricmp(p, PROCESS_COUNTER) == 0)

 {

 // look backwards for the counter number

for( p2=p-2; isdigit(*p2); p2--) ;

 strcpy( szSubKey, p2+1 );

 }

  else if (stricmp(p, PROCESSID_COUNTER) == 0)

 {

 // look backwards for the counter number

for( p2=p-2; isdigit(*p2); p2--) ;

 dwProcessIdTitle = atol( p2+1 );

 }

 // next string

 p += (strlen(p) + 1);

 }

本文关键:枚举本地远程NT系统进程
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top