Solved

Get a Service Info from Task Manager

Posted on 2006-07-20
5
284 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
  • 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unable to start eclipse ? 17 141
FMX TCameraComponent Problem 2 69
designing in object programming 12 76
DCT of  2D array using fftw in c++ 9 39
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

776 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