【问题标题】:Invoking a method when Windows Explorer opens a given folder当 Windows 资源管理器打开给定文件夹时调用方法
【发布时间】:2013-02-11 12:59:50
【问题描述】:

当用户在 Windows 资源管理器中打开文件夹时,我想执行一些 C# 方法。

这样的事情怎么办?

【问题讨论】:

  • 自动启动的 Windows 服务。使用计时器跟踪所有当前正在执行的进程,并查找标题包含所需文件夹的 iexplorer.exe 进程。
  • 仅仅因为答案可能是“否”并不意味着问题是模棱两可、含糊不清、不完整、过于宽泛或修辞。
  • 也许这些对你有帮助:1, 2
  • 可以尝试使用这个stackoverflow.com/questions/2118452/… 并在其中实现一个函数。

标签: c# events directory windows-explorer


【解决方案1】:

我不确定,但这是我会做/尝试的,

有一个 C# 程序在登录 Open C# application on log on 时启动,或者只是让你的程序以某种方式运行并使用 FileSystemWatcher Class,你可以使用 LastAccess 通知过滤器并让你的 C# 代码得到执行。

    // Create a new FileSystemWatcher and set its properties.
    FileSystemWatcher watcher = new FileSystemWatcher();
    watcher.Path = "folder path";

     /* Watch for changes in LastAccess and LastWrite times, and
       the renaming of files or directories. */
    watcher.NotifyFilter = NotifyFilters.LastAccess;

    // add event handler

希望这会有所帮助。

【讨论】:

  • 这并不能告诉您该文件夹是由 Windows 资源管理器打开还是由某个任意进程访问。
猜你喜欢
  • 2012-09-29
  • 1970-01-01
  • 2013-07-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多