0

Hi I would like to know/steps how to get the filename opened from the process using windows api C/C++ .

For example If I have opened Text1.txt , Text2.txt and Text3.txt files.. they have 3 process running in background with executables named Notepad.exe.

how can I retrieve filenames with absolute paths of "Text1.txt" ,"Text2.txt","Text3.txt"? using GetCurrentProcess() / GetCurrentProcessId()/ by any other functions..

Note: Filenames are dynamic

User1611
  • 1,081
  • 4
  • 18
  • 27
  • 3
    Please clarify what you want exactly. Your question is not clear. – Jabberwocky Mar 01 '16 at 07:42
  • 3
    You could probably find your answer [Here](http://stackoverflow.com/questions/177146/how-do-i-get-the-list-of-open-file-handles-by-process-in-c) – dvhh Mar 01 '16 at 07:44
  • What is "the process" you're referring to? If you opened 3 text files with Notepad, there'd be 3 processes, not one, and `Notepad.EXE` is the common **executable** (not process). – MSalters Mar 01 '16 at 08:18
  • Are you asking how to determine the default handler for a given file type or filename? – Sean Comeau Mar 01 '16 at 08:28
  • Unless a program explicitly exposes what file it has opened with an automation interface, there is no way to find out what file handles it owns. The SysInternals' Handle utility uses an undocumented kernel hack to enumerate the handle table. Not that it is actually useful, you see *everything*. Not being able to find out is very much by design, handle recycle attacks are nasty. – Hans Passant Mar 01 '16 at 10:34
  • Sorry for not making it clear... yes you are right.. there will be three process running and from the processes/PID.. I would like to extract the filename that triggered the process ie Text1.txt , Text2.txt , Text3.txt... is that possible? GetCurrentProcessId() function will return the PID... from there how can I get the filename ... this is what my question is.. – User1611 Mar 01 '16 at 17:03
  • Typically the command line will contain this information, I'm not sure offhand how to find out what the command line was, but it should be possible since Task Manager can do it. Of course you'll still need to know the command syntax for the executable, but 99% of the time the filename is the only argument. – Harry Johnston Mar 02 '16 at 10:52

0 Answers0