开发者

List opened files

开发者 https://www.devze.com 2023-02-03 15:39 出处:网络
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:

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开发者_StackOverflow中文版 are created/modified/updated or deleted, but not opened.

How I can do it?


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).


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消