I want to track the files which are opened by the user, and select them by one particular extension. If the opened file has that extension, then I want to assign it's file path to a variable for further processing. Example applications are very cpu demanding. Is there an easy, efficient way to do that?
Asked
Active
Viewed 92 times
1
-
http://stackoverflow.com/questions/14779616/filesystemwatcher-used-to-watch-for-folder-file-open/14779729#14779729 read this – Arindam Nayak Oct 13 '14 at 16:51
-
I saw it. It looks for a particular folder, but I wanna watch the whole system, especially flash drives. And also the last answer suggests C++. I want to use C#. – Oct 13 '14 at 16:53
-
Perhaps instead of monitoring the entire system, you could associate .ppt / .pptx files with your application. That sounds much simpler. – Moby Disk Oct 13 '14 at 16:55
-
2associate file extension to your app: http://stackoverflow.com/questions/2681878/associate-file-extension-with-application – Jeff Oct 13 '14 at 16:58
-
Otherwise, you will likely have to write a FS filter driver to watch for OpenFile(..) calls, similar to how Sysinternals ProcessMonitor works (however ProcessMonitor watches everything). – Jeff Oct 13 '14 at 17:01
-
If that is the case, and you are certain you need to monitor opening files system wide, then you will likely be forced to write a file system filter driver. – Jeff Oct 13 '14 at 17:19
-
Here is an example: http://www.codeproject.com/Articles/43586/File-System-Filter-Driver-Tutorial – Jeff Oct 13 '14 at 17:21
-
perhaps there may be a way to hook onto Powerpoint, and get notifications through Powerpoint. Maybe look into Powerpoint automation. – Jeff Oct 13 '14 at 17:26
-
can we chat for 5-10 minutes if u wouldn't mind? – Oct 13 '14 at 17:29
-
Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/62989/discussion-between-jeff-and-m1clee). – Jeff Oct 13 '14 at 17:29
1 Answers
1
System wide monitoring of file-->open events (including network drives, thumb drives, etc) would require you to write a FS filter driver.
Since you have access to the machine, and you definitely need system wide access, you could simply write a simple app that will be associated with the Powerpoint extensions, perform the copy, then open Powerpoint using the filepath as a command line argument. It would look similar to the following:
using System;
using System.Windows;
using System.Diagnostics;
using System.IO;
namespace WpfApplication1
{
internal class MainWindow : Window
{
public MainWindow()
{ }
[STAThread()]
static void Main(string[] args)
{
if (args.Length == 0)
{
// [ show error or print usage ]
return;
}
if (!File.Exists(args[0]))
{
// [ show error or print usage ]
return;
}
// Perform the copy
FileInfo target = new FileInfo(args[0]);
string destinationFilename = string.Format("X:\\ExistingFolder\\{0}", target.Name);
File.Copy(target.FullName, destinationFilename);
// You may need to place the filename in quotes if it contains spaces
string targetPath = string.Format("\"{0}\"", target.FullName);
string powerpointPath = "[FullPathToPowerpointExecutable]";
Process powerpointInstance = Process.Start(powerpointPath, targetPath);
// This solution is using a wpf windows app to avoid
// the flash of the console window. However if you did
// wish to display an accumulated list then you may choose
// to uncomment the following block to display your UI.
/*
Application app = new Application();
app.MainWindow = new MainWindow();
app.MainWindow.ShowDialog();
app.Shutdown(0);
*/
Environment.Exit(0);
}
}
}
Hope this helps.

Jeff
- 2,495
- 18
- 38
-
if I change the default WPF function whose name is "public MainWindow()" to "static void Main(strings[] args)" then it gives an error. if I change it something else, the function doesnt start. – Oct 13 '14 at 20:30
-
Create a new WPF application and delete generated files (App.config, App.xaml, App.xaml.cs, MainWindow.xaml, and MainWindow.xaml.cs). Next, add a new class called 'MainWindow' and clear all generated code. Paste the code above and it will compile. Modify paths, and begin testing. (I tested it prior to making the post) – Jeff Oct 13 '14 at 20:37