Reputation: 3754
I've read some posts about my issue, but I haven't find a right solution. I would have a complete list of current files in use, for example:
*.mp3 files opened by Windows Media Player
*.txt files opened by Notepad.exe
*.avi files opened by VLC etc...
With FileWatcher system I can get files that are created/modified/updated or deleted, but not opened.
How I can do it?
Upvotes: 2
Views: 953
Reputation: 36473
I'd suggest the simplest method would be to use the Handle command-line tool from the same people as Process Explorer.
You could maybe invoke the process from your code, and then parse the output, which is basically just a big list of open files (and registry entries) divided into sections with the process that opened the file as the header.
I think that under the hood Handle uses the NT Object Manager API, so that may be worth looking into if you need to do the whole thing yourself.
Upvotes: 0
Reputation: 66389
Most you can achieve with simple code is iterate over all Processes and read their Title
- most programs will put the current file in use inside their title e.g. Notepad will have window title of "TextFile.txt - Notepad".
If you like I can pull together some quick example.
To achieve exactly what you want though, you'll have to "hook" into the processes in some low level way and see their internals - Frédéric Hamidi reply pretty much covers this.
Upvotes: 0
Reputation: 262939
You can use the Process Explorer tool from Sysinternals to obtain that information, but I don't think you can easily do the same by code (short of reimplementing Process Explorer itself).
Upvotes: 2