nbsp; 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 );