• C

I need a way to check to see if msaccess.exe is running.

I looked in previous questions and the solution was a link to MS KB that is no longer available.

"How To Enumerate Applications Using Win32 APIs" is what the solution refered to. I can't seem to find a definative solution in MS. Does anyone know what API(s) I need to find out whether or not a user has a particular program up and running?


Who is Participating?
jkrConnect With a Mentor Commented:
You will find equivalent code at http://msdn2.microsoft.com/en-us/library/ms682623.aspx ("Enumerating All Processes"):

#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include "psapi.h"

void PrintProcessNameAndID( DWORD processID )
    TCHAR szProcessName[MAX_PATH] = TEXT("<unknown>");

    // Get a handle to the process.

                                   FALSE, processID );

    // Get the process name.

    if (NULL != hProcess )
        HMODULE hMod;
        DWORD cbNeeded;

        if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod),
             &cbNeeded) )
            GetModuleBaseName( hProcess, hMod, szProcessName,
                               sizeof(szProcessName)/sizeof(TCHAR) );

    // Print the process name and identifier.

    _tprintf( TEXT("%s  (PID: %u)\n"), szProcessName, processID );

    CloseHandle( hProcess );

void main( )
    // Get the list of process identifiers.

    DWORD aProcesses[1024], cbNeeded, cProcesses;
    unsigned int i;

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

    // Calculate how many process identifiers were returned.

    cProcesses = cbNeeded / sizeof(DWORD);

    // Print the name and process identifier for each process.

    for ( i = 0; i < cProcesses; i++ )
        if( aProcesses[i] != 0 )
            PrintProcessNameAndID( aProcesses[i] );
scuzz1Author Commented:
I'm getting complaints about unresolved external symbols:

copybart.obj : error LNK2001: unresolved external symbol _EnumProcesses@12
copybart.obj : error LNK2001: unresolved external symbol _GetModuleBaseNameA@16
copybart.obj : error LNK2001: unresolved external symbol _EnumProcessModules@16

I'm using Visual C++ 6.0 and my project is a Win32 Console App using C as my source code.

I looked in psapi.h but don't see anything like those.

You need to link with 'psapi.lib' - either add that to your Visual Studio project or use

#pragma comment(lib,"psapi.lib")
scuzz1Author Commented:
I had to go find a copy of psapi.lib. It works great. Thanks a lot.
I was close before but I was in the reference section and it just showed the function. I needed to go to the using psapi section.
Even then it does not say anything about psapi.lib.

Thanks again.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.