Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using PdhExpandCounterPath On XP-SP2

Status
Not open for further replies.

TGandon

Programmer
Aug 10, 2005
35
0
0
GB
Question originally submitted on VisualBasic(Microsoft)Win32API forum

I use the ProcessList function below to retrieve a list of all processes called E2eDgCnx.

Up until now, this has performed adequately but we are about to implement XP SP2 and in testing this now fails.

Code:
Public Declare Function PdhExpandCounterPath Lib "Pdh.Dll" Alias "PdhExpandCounterPathA" (ByVal szWildCardPath As String, ByVal mszExpandedPathList As String, pcchPathListLength As Long) As Long

Public Function ProcessList()As String

Dim lngReturnValue As Long, lngBufferLen As Long
Dim strSearchPath As String, strExpandedPath As String

lngBufferLen = 8192
strExpandedPath = String(lngBufferLen, vbNullChar)
strSearchPath = "\Process(E2eDgCnx)\% Processor Time"

lngReturnValue = PdhExpandCounterPath(strSearchPath, strExpandedPath, lngBufferLen)

ProcessList = Left(strExpandedPath, lngBufferLen)

End Sub

I've carried out some testing using multiple copies of Notepad as the target
ie. strSearchPath = "\Process(notepad)\% Processor Time" and found

pre-SP2 returns
\Process(notepad)\% Processor Time
repeated in chronological order for each instance of notepad (or nothing if notepad is not running)

SP2 returns the single result
\\ComputerName\Process(notepad)\% Processor Time
regardless of the number of notepads running (and even if notepad is not running)

If I try strSearchPath = "\Process(*)\% Processor Time" and then filter the results for "(notepad"

Pre-SP2 again returns
\Process(notepad)\% Processor Time
repeated for each instance of notepad (or nothing if notepad is not running) in chronological order of notepad launches

SP2 returns
...
\\ComputerName\Process(notepad#2)\% Processor Time
\\ComputerName\Process(notepad#1)\% Processor Time
\\ComputerName\Process(notepad)\% Processor Time
in reverse chronological order of notepad launches
or nothing if notepad is not running

I don't really want have to double up my functions to cater for different service packs so can anyone advise how to retieve the required data in chronological order.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top