I need to create an application that when a user copies a file into an specific folder, my application will be activated and the file will be changed, also, when the user reads back any file in the folder, changes will also be made to the file.
我需要创建一个应用程序,当用户将文件复制到特定文件夹时,我的应用程序将被激活并且文件将被更改,当用户回读文件夹中的任何文件时,也会对文件进行更改。文件。
Is it possible?
可能吗?
I'll use .net for this.
我会用.net来做这个。
I think the folder C:\WINDOWS\assembly is somehow like this?
我认为文件夹C:\ WINDOWS \ assembly就是这样的?
Any help will be appreciated! Thanks!
任何帮助将不胜感激!谢谢!
4 个解决方案
#1
2
Well, I'm sure you could write an explorer extension that would do that, but the more typical method that I know of is to write a windows service that monitors the directory in question using the FileSystemWatcher class to monitor events. The service can then perform the requested actions (or spawn an executable to do it).
好吧,我确定你可以编写一个可以做到这一点的资源管理器扩展,但我知道的更典型的方法是使用FileSystemWatcher类编写一个监视相关目录的Windows服务来监视事件。然后,该服务可以执行所请求的操作(或生成可执行文件来执行此操作)。
One caveat I have noticed is that sometimes the file watcher can miss events if a lot of activity occurs at once (as of .net 2.0 - haven't checked 3.5).
我注意到的一个警告是,如果一次发生大量活动,有时文件观察者可能会错过事件(截至.net 2.0 - 尚未检查3.5)。
If you use that method, make sure you check the directory contents yourself when you receive a change notification rather than relying on what the filewatcher tells you. I ended up combining the filewatcher event handling with an infrequent poll just to make sure I didn't miss anything.
如果您使用该方法,请确保在收到更改通知时自己检查目录内容,而不是依赖filewatcher告诉您的内容。我最终将filewatcher事件处理与不常见的民意调查结合起来,以确保我没有错过任何东西。
#2
1
You can detect users copying files into a folder with a service that uses FileSystemWatcher. Altering the contents of a file when an app reads the file requires viral techniques that patch the operating system. Like a rootkit or a file system filter driver. Not something I'd recommend considering, alter the file after it was written.
您可以检测用户将文件复制到使用FileSystemWatcher的服务的文件夹中。当应用程序读取文件时更改文件的内容需要修补操作系统的病毒技术。像rootkit或文件系统筛选器驱动程序。不是我建议考虑的东西,在写完文件后改变它。
c:\windows\assembly contains the GAC. .NET installs a shell extension handler that hides the contents of the folder. The folder is otherwise quite accessible, the shell extension handler only works when you look at the folder with Windows Explorer. Writing shell extension handlers with .NET is strongly discouraged by Microsoft, the framework also completely lacks support.
c:\ windows \ assembly包含GAC。 .NET安装一个shell扩展处理程序,用于隐藏文件夹的内容。该文件夹在其他方面非常容易访问,只有在使用Windows资源管理器查看该文件夹时,shell扩展处理程序才有效。 Microsoft强烈建议不要使用.NET编写shell扩展处理程序,该框架也完全缺乏支持。
#3
0
You can monitor for changes with FileSystemWatcher.
您可以使用FileSystemWatcher监视更改。
You can configure the component to watch either an entire directory and its contents or a specific file or set of files within a given directory. The FileSystemWatcher component raises an event whenever a file or subdirectory within the specified root directory is created, deleted, renamed, or changed in some other way. The types of changes that the component monitors include changes in the file's or subdirectory's attributes, size, last write time, last access time, and security settings.
您可以将组件配置为监视整个目录及其内容,或者查看给定目录中的特定文件或文件集。只要以某种其他方式创建,删除,重命名或更改指定根目录中的文件或子目录,FileSystemWatcher组件就会引发事件。组件监视的更改类型包括文件或子目录的属性,大小,上次写入时间,上次访问时间和安全设置的更改。
#4
0
The closest thing you'll get in .net is the FileSystemWatcher class, it will monitor for changes (creating and writing) but not for reading activity.
你将在.net中得到的最接近的东西是FileSystemWatcher类,它将监视更改(创建和编写),但不监视读取活动。
There are many samples online and on MSDN
在线和MSDN上有很多样本
http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx
#1
2
Well, I'm sure you could write an explorer extension that would do that, but the more typical method that I know of is to write a windows service that monitors the directory in question using the FileSystemWatcher class to monitor events. The service can then perform the requested actions (or spawn an executable to do it).
好吧,我确定你可以编写一个可以做到这一点的资源管理器扩展,但我知道的更典型的方法是使用FileSystemWatcher类编写一个监视相关目录的Windows服务来监视事件。然后,该服务可以执行所请求的操作(或生成可执行文件来执行此操作)。
One caveat I have noticed is that sometimes the file watcher can miss events if a lot of activity occurs at once (as of .net 2.0 - haven't checked 3.5).
我注意到的一个警告是,如果一次发生大量活动,有时文件观察者可能会错过事件(截至.net 2.0 - 尚未检查3.5)。
If you use that method, make sure you check the directory contents yourself when you receive a change notification rather than relying on what the filewatcher tells you. I ended up combining the filewatcher event handling with an infrequent poll just to make sure I didn't miss anything.
如果您使用该方法,请确保在收到更改通知时自己检查目录内容,而不是依赖filewatcher告诉您的内容。我最终将filewatcher事件处理与不常见的民意调查结合起来,以确保我没有错过任何东西。
#2
1
You can detect users copying files into a folder with a service that uses FileSystemWatcher. Altering the contents of a file when an app reads the file requires viral techniques that patch the operating system. Like a rootkit or a file system filter driver. Not something I'd recommend considering, alter the file after it was written.
您可以检测用户将文件复制到使用FileSystemWatcher的服务的文件夹中。当应用程序读取文件时更改文件的内容需要修补操作系统的病毒技术。像rootkit或文件系统筛选器驱动程序。不是我建议考虑的东西,在写完文件后改变它。
c:\windows\assembly contains the GAC. .NET installs a shell extension handler that hides the contents of the folder. The folder is otherwise quite accessible, the shell extension handler only works when you look at the folder with Windows Explorer. Writing shell extension handlers with .NET is strongly discouraged by Microsoft, the framework also completely lacks support.
c:\ windows \ assembly包含GAC。 .NET安装一个shell扩展处理程序,用于隐藏文件夹的内容。该文件夹在其他方面非常容易访问,只有在使用Windows资源管理器查看该文件夹时,shell扩展处理程序才有效。 Microsoft强烈建议不要使用.NET编写shell扩展处理程序,该框架也完全缺乏支持。
#3
0
You can monitor for changes with FileSystemWatcher.
您可以使用FileSystemWatcher监视更改。
You can configure the component to watch either an entire directory and its contents or a specific file or set of files within a given directory. The FileSystemWatcher component raises an event whenever a file or subdirectory within the specified root directory is created, deleted, renamed, or changed in some other way. The types of changes that the component monitors include changes in the file's or subdirectory's attributes, size, last write time, last access time, and security settings.
您可以将组件配置为监视整个目录及其内容,或者查看给定目录中的特定文件或文件集。只要以某种其他方式创建,删除,重命名或更改指定根目录中的文件或子目录,FileSystemWatcher组件就会引发事件。组件监视的更改类型包括文件或子目录的属性,大小,上次写入时间,上次访问时间和安全设置的更改。
#4
0
The closest thing you'll get in .net is the FileSystemWatcher class, it will monitor for changes (creating and writing) but not for reading activity.
你将在.net中得到的最接近的东西是FileSystemWatcher类,它将监视更改(创建和编写),但不监视读取活动。
There are many samples online and on MSDN
在线和MSDN上有很多样本
http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx