获取一个已知进程名的进程该怎么操作?如果要以进程名查询该进程是否存在,怎么操作?详细,谢谢~~~

解决方案 »

  1.   

    看看msdn里一下3个函数的解释 你就知道了
    Createtoolhelpsnapshot
    process32first
    process32next
      

  2.   

    遍历所有进程,比较进程名。微软的代码:#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] );
    }
      

  3.   

    获得快照,遍历进程列表,字符串比较,获得进程ID,OpenProcess获得快照的相关函数,CreateToolhelp32SnapshotMSDN里有例子