+ Reply to Thread
Results 1 to 2 of 2

Thread: Ho to get process name from specified process ID?

  1. #1

    Ho to get process name from specified process ID?

    Ho to get process name from specified process ID?

  2. #2
    Following is the example:

    Code:
    CString GetProcessNameFromProcessID(DWORD dwProcessID)
    {
    	CString strProcessName ;
    	HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,
    								   FALSE, dwProcessID) ;
    
    	// Get the process name.
    	if (NULL != hProcess )
    	{
    		HMODULE hMod ;
    		DWORD cbNeeded ;
    
    		if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod), &cbNeeded) )
    		{
    			char szProcessName[MAX_PATH] = { 0 } ;
    			GetModuleBaseName( hProcess, hMod, szProcessName, 
    							   sizeof(szProcessName) ) ;
    
    			strProcessName = szProcessName;
    			OutputDebugString(szProcessName) ;
    			OutputDebugString("\r\n") ;
    		}
    
    		CloseHandle( hProcess ) ;
    	}
    
    	return strProcessName ;
    }
    
    CString strProcessName = GetProcessNameFromProcessID(GetCurrentProcessId()) ;

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts