?
Solved

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

Posted on 2007-07-31
4
Medium Priority
?
255 Views
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?

Jim

0
Comment
Question by:scuzz1
  • 2
  • 2
4 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 2000 total points
ID: 19601470
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.

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

    // 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] );
}
0
 

Author Comment

by:scuzz1
ID: 19601744
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.

Jim
0
 
LVL 86

Expert Comment

by:jkr
ID: 19601803
You need to link with 'psapi.lib' - either add that to your Visual Studio project or use

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

Author Comment

by:scuzz1
ID: 19601958
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.
Jim
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

850 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