Solved

Get a Service Info from Task Manager

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Cross compile release version of c++ program for linux 2 131
Socket Programming (Unix) 8 119
Deploying Open Type Font (.OTF) company wide ? 3 84
I could not build boost code, 10 79
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
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 tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

896 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now