Solved

Get a Service Info from Task Manager

Posted on 2006-07-20
5
296 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 500 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

731 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