in
Windows Task Manager --> Processes
there is a list of running exe files.
I am going to write a program that lists these running exe files.
How can I obtain the list?
I use Windows XP :$
& Windows API!:)

in
Windows Task Manager --> Processes
there is a list of running exe files.
I am going to write a program that lists these running exe files.
How can I obtain the list?
I use Windows XP :$
& Windows API!:)

Something like this? - Just an old program I had laying around. Needs the "psapi.h", "psapi.lib" and "psapi.dll".

int FindPIDs()
{
DWORD ProcessesIDs[1000], cbNeeded, cProcesses; 
unsigned int i;
//The default of <unknown> is given so that if GetModuleBaseName does not return 
//the base name of the module then <unknown> will be printed instead of the base name.
 
TCHAR szProcessName[50] = TEXT("<unknown>");
 

EnumProcesses( ProcessesIDs, sizeof(ProcessesIDs), &cbNeeded ) ;
 
// Calculate how many process identifiers were returned.
cProcesses = cbNeeded / sizeof(DWORD);
 
// This for loop will be enumerating each process.
for ( i = 0; i < cProcesses; i++ )
{
// Get a handle to the process. The process to which the handle will be returned //will depend on the variable i.
    HANDLE hProcess =OpenProcess( PROCESS_QUERY_INFORMATION |PROCESS_VM_READ, FALSE, ProcessesIDs[i]);
 
    // Get the process name.
    if (NULL != hProcess )
        {
        GetModuleBaseName( hProcess, NULL, szProcessName, sizeof(szProcessName)/sizeof(TCHAR) );
        }
 
    // Print the process name and identifier.
    cout << "Processname= " << szProcessName << endl;
    cout << "PID = " << ProcessesIDs[i];
    cout << endl << endl;
    
    //Every handel is to be closed after its use is over.
    CloseHandle( hProcess);
    //End of for loop.
    }
    
    return 0;
}

Usefull in anyway?

Thank you very much! It works :)
can't rep u cos my rep power == 0

And I have another question
how can I kill a process?
or change its priority?

Don't use psapi statically, its not on all OS
See MSDN sample to list processes

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.