I'm dumping info about all the processes running on my pc into a .txt file. To do this I execute handle.exe from my java application. The file contains all the running processes in this format:
RuntimeBroker.exe pid: 4756
4: Key HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image
8: Event
10: WaitCompletionPacket
1C: IRTimer
20: WaitCompletionPacket
24: IRTimer
28: File \Device\CNG
--
SearchIndexer.exe pid: 5616
4: Event
8: WaitCompletionPacket
C: IoCompletion
1C: IRTimer
20: File \Device\0000007s
22: Directory
I need to get the name of the process that is using a given device i.e. if I'm looping through the file searching for the string "\Device\0000007s", I need to get the name of the process and the process id which is a few lines above. Does anybody know how could I do this? The processes are delimited by a line of dashes -- in the file. Bear in mind that the file is massive, this is just an example.