?
Solved

Get a Service Info from Task Manager

Posted on 2006-07-20
5
Medium Priority
?
314 Views
Last Modified: 2013-12-03
Hi,

i used the code below to pass over all the processes and get their info.
the problem that when the process is a service then there is no info like in process.

how can i get an info on services:
- process handle
- process name
- process full name
- process Memory Info
- get process IO info

and integrate it in my code?

see my remark inside the code below.

thanks
efratk


void CProcessView::InitializeProcessMaps()
{

    // Get the list of process identifiers.

    DWORD aProcesses[1024], cbNeeded, cProcesses;
    unsigned int i;
    char szProcessName[MAX_PATH] = "unknown";
    char szProcessFullPath[MAX_PATH] = "unknown";

    if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
        return;

    // Calculate how many process identifiers were returned.

    cProcesses = cbNeeded / sizeof(DWORD);

    // Get the name of the modules for each process.
      
      for ( i = 0; i < cProcesses; i++ )
      {
            HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, aProcesses[i] );

/**************************
here process ids of services returned with hProcess == NULL thus no info about it!!!!!!!!!!!!!!!!!
************************* */            
             if ( hProcess )
            {
                  HMODULE hMod;
                  DWORD cbNeeded;

                  if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod), &cbNeeded) )
                  {                        
                        /* GET  PROCESS INFO... /
                        //process id in:  aProcesses[i];
                        //process handle in: hProcess;
                        //Get Name
                        GetModuleBaseName( hProcess, hMod, szProcessName, sizeof(szProcessName) );
                        //Get the full path to the module's file.
                        GetModuleFileNameEx( hProcess, hMod, szProcessFullPath, sizeof(szProcessFullPath));
                        //Get Process Memory Info                  
                        GetProcessMemoryInfo( hProcess, &pvwByID->psMemCounters, sizeof(pvwByID->psMemCounters));
                        //Get Process IO info
                        GetProcessIoCounters( hProcess, &pvwByID->psIOCounters);
                  }
            }
      }

      return;
}
0
Comment
Question by:efratk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 17146497
Which user account are you rinng that under? Right from the top off my head, I'd say that using

          HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION, FALSE, aProcesses[i] );

should fix your problem, since PROCESS_VM_READ is hardly required to gather the info you're interested in.
0
 

Author Comment

by:efratk
ID: 17162440
sorry,
i tested it without the  PROCESS_VM_READ flag and it still rerurned with hProcess = NULL;

any other idea?
0
 

Author Comment

by:efratk
ID: 17192204
i tested it also without the  PROCESS_QUERY_INFORMATION flag and it still rerurned with hProcess = NULL;

does anyone have an idea?


0
 
LVL 86

Accepted Solution

by:
jkr earned 2000 total points
ID: 17194550
Since that is a service, one option might be to enable the debug privilege - try calling

BOOL    EnableDebugPriv (   BOOL    bEnable)
{
   HANDLE           hToken;
   TOKEN_PRIVILEGES tp;

   if   (   !OpenProcessToken   (   GetCurrentProcess   (),
                                    TOKEN_ADJUST_PRIVILEGES,
                                    &hToken
                                )
        )   return  (   FALSE);


   tp.PrivilegeCount    =   1;
   
   LookupPrivilegeValue (   NULL,
                            SE_DEBUG_NAME,
                            &tp.Privileges  [   0].Luid
                        );

   tp.Privileges    [   0].Attributes   =       bEnable
                                            ?   SE_PRIVILEGE_ENABLED
                                            :   0;

   AdjustTokenPrivileges    (   hToken,
                                FALSE,
                                &tp,
                                sizeof  (   tp),
                                NULL,
                                NULL
                            );

   return   (   GetLastError()  ==   ERROR_SUCCESS);
}

e.g. like

EnableDebugPriv ( TRUE);
0
 

Author Comment

by:efratk
ID: 17210209
thanks a lot jkr. i used the EnableDebugPriv and it helped.

great!!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question