如何从进程名获得进程ID

<textarea cols="86" rows="23" name="code" class="cpp">#include &lt;ntddk.h&gt; #include "ntifs.h" HANDLE RetrivePID( char* ProcessName ) { PEPROCESS PeProcess = NULL; PLIST_ENTRY pNextEntry, pListHead; PeProcess = PsGetCurrentProcess(); if(!PeProcess) { DbgPrint( "[ALARM] -&gt; Cannot find 'System' process!" ); return (HANDLE)-1; } if( IsListEmpty( &amp;PeProcess-&gt;ActiveProcessLinks ) ) DbgPrint("[ALARM] -&gt; No processes found!"); else { pListHead = &amp;PeProcess-&gt;ActiveProcessLinks; pNextEntry = pListHead-&gt;Flink; while(pNextEntry != pListHead) { PeProcess = CONTAINING_RECORD( pNextEntry,EPROCESS,ActiveProcessLinks ); if(PeProcess-&gt;ActiveThreads) if( !IsListEmpty( &amp;PeProcess-&gt;ThreadListHead ) ) { //if( _strnicmp( PeProcess-&gt;ImageFileName, ProcessName ,strlen(ProcessName) ) == 0 ) // return PsGetProcessId( PeProcess ); DbgPrint("Process name: %s - PID:%d", PeProcess-&gt;ImageFileName, PeProcess-&gt;UniqueProcessId); } PeProcess = NULL; pNextEntry = pNextEntry-&gt;Flink; } } return (HANDLE)-1; } VOID Unload(IN PDRIVER_OBJECT DriverObject) { DbgPrint("Test Driver :: Unload"); } NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject,IN PUNICODE_STRING RegistryPathName) { DbgPrint("Test Driver :: DriverEntry"); // Test function RetrivePID("notepad.exe"); DriverObject-&gt;DriverUnload = Unload; return STATUS_SUCCESS; }</textarea>

你可能感兴趣的:(如何从进程名获得进程ID)