C# 列出当前打开的文件和程序
有没有办法获取所有打开的应用程序的列表和所有打开的文件的列表?对于文件,我只需要我打开的文件(文档等),而不是操作系统的打开系统文件。应用程序也是如此(仅浏览器、文档处理器等)。
我已经尝试了 Windows API 中的各种功能,例如 EnumWindows,但我无法得到我想要的。
我的最终目标的一个例子是拥有这样的列表:
应用程序
Microsoft Word, 记事本, Mozilla Firefox
文件
foo.txt, foo.mp3, foo.doc
我需要的只是名称,我不需要句柄等(尽管我确信我必须使用它们来获得我想要的东西)
Is there a way I can get a list of all open applications and a list of all open files? For the files I only need the files that I opened (documents etc) not OS's open system files. The same for the applications (only browsers, document processors etc).
I already tried various functions from the Windows API like EnumWindows but I couldn't get what I wanted.
An example of what my ultimate goal would be, is to have lists like this:
Applications
Microsoft Word,
Notepad,
Mozilla Firefox
Files
foo.txt,
foo.mp3,
foo.doc
What I need is just the names, I don't need handles etc (even though I'm sure I'll have to use them to get what I want)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以获得正在运行的进程及其信息的列表。
查看进程是否由用户或系统打开的唯一方法(据我所知)是检查其所有者。如果它是系统,那么它不是由用户运行:
对于打开的文件列表,可以使用托管代码来完成,但这在某种程度上是困难的。这是 codeproject 上的示例 演示了相同的问题
You can get a list of running processes with their information
The only method (That I know) to see if the process is opened by user or system is to check it's owner. If it's system, then it's not run by user:
For the list of opened files, It is possible to do using Managed Code which is somehow hard. Here is an example on codeproject demonstrating the same matter
您可以使用 Process.GetProcesses() 获得正在运行的进程列表: http:// msdn.microsoft.com/en-us/library/1f3ys1f9.aspx
但是,如果他们公开了您知道的一些自动化接口,您就可以让他们打开文件。
You can have a list of running processes with Process.GetProcesses(): http://msdn.microsoft.com/en-us/library/1f3ys1f9.aspx
But you can have the file they have open if they exposes some automation interface you know.