Link to home
Start Free TrialLog in
Avatar of mycuti08
mycuti08

asked on

Determine the PDH process names

Hi,

I'm working on PDH (Performance Data Helper). The commands asks for the process name. The name is processed in a specific way such as adding index to the processes that have same names, remove the ".exe". However, I saw some instances whose names were truncated differently.
For example, the process "GoogleDesktopIndex.exe" is trunctated to "GoogleDesktopIndex", but the other process name such as "smtpmanualproc.exe" is truncated to "smtpmanualproc.ex".

The name length is not the determining factor in this case. I just wonder if there is any documentation about the PDH process name processing?

Thanks
Avatar of DanRollins
DanRollins
Flag of United States of America image

When I browse the list, all of the items appear to match the expected naming.  Is there any chance that you are accidentally truncating the text yourself?
Avatar of mycuti08
mycuti08

ASKER

No, absoutely not. Because the process named "smtpmanualproc.exe" got truncated to "smtpmanualproc.ex", and sometimes I saw the truncated names as such "xxxxxx." without the "exe". It turned out the process names was "xxxxxx.exe" and got truncated by removing only "exe" not the dot. At first, I thought that there were a certain length below which the ".exe" was truncated and above it the full name was cut off to a certain length (no matter the extension, like the two examples mentioned above), but then I saw the very long name which was truncated the "standard way": ripped off the ".exe". That perplexed me, indeed.
Try to list the processes the way the task manager does that. See http://msdn.microsoft.com/en-us/library/ms682623.aspx ("Enumerating All Processes") and the sample code it comes with:
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include <psapi.h>
 
void PrintProcessNameAndID( DWORD processID )
{
    TCHAR szProcessName[MAX_PATH] = TEXT("<unknown>");
 
    // Get a handle to the process.
 
    HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
                                   PROCESS_VM_READ,
                                   FALSE, processID );
 
    // Get the process name.
 
    if (NULL != hProcess )
    {
        HMODULE hMod;
        DWORD cbNeeded;
 
        if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod), 
             &cbNeeded) )
        {
            GetModuleBaseName( hProcess, hMod, szProcessName, 
                               sizeof(szProcessName)/sizeof(TCHAR) );
        }
    }
 
    // Print the process name and identifier.
 
    _tprintf( TEXT("%s  (PID: %u)\n"), szProcessName, processID );
 
    CloseHandle( hProcess );
}
 
void main( )
{
    // Get the list of process identifiers.
 
    DWORD aProcesses[1024], cbNeeded, cProcesses;
    unsigned int i;
 
    if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
        return;
 
    // Calculate how many process identifiers were returned.
 
    cProcesses = cbNeeded / sizeof(DWORD);
 
    // Print the name and process identifier for each process.
 
    for ( i = 0; i < cProcesses; i++ )
        if( aProcesses[i] != 0 )
            PrintProcessNameAndID( aProcesses[i] );
}

Open in new window

I wonder about how you are determining that this truncation exists.  What method do you use to obtain the list in which the truncation occurs?

It occurs to me that the "friendly name" is actually the end result of a much longer name that includes the local computer, the directory path in which the image file resides, and so forth.   Perhaps that longer name hit some maximum and was truncated by the naming logic.  

Check out that possibility by tracking down the full path of the executable that ends up with one of these truncated names.  See if you can see a pattern (very long path name, computer name with and embedded apostrophe, etc.)
ASKER CERTIFIED SOLUTION
Avatar of mycuti08
mycuti08

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial