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

Posted on 2007-07-31
Last Modified: 2010-05-18
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?


Question by:scuzz1
    LVL 86

    Accepted Solution

    You will find equivalent code at ("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.

        HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
                                       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] );

    Author Comment

    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.

    LVL 86

    Expert Comment

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

    #pragma comment(lib,"psapi.lib")

    Author Comment

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
    This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
    The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
    The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

    737 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

    21 Experts available now in Live!

    Get 1:1 Help Now