FileSystemWatcher used to watch for folder/file openMonitor file open c# .NetFileSystemWatcher doesn't fire for Opened files C#File System Watcher of Powershell on Opening a FolderTracking files of a particular extensionWindows, Watching a folder in C#How Many Times A File's Been OpenedDetect whenever a specific file type gets openedHow to create Excel (.XLS and .XLSX) file in C# without installing Ms Office?Detecting moved files using FileSystemWatcherHow to delete all files and folders in a directory?FileSystemWatcher Changed event is raised twiceFilter FileSystemWatcher changed eventsFileSystemWatcher - 3 events during File copyFileSystemWatcher doesn't fire for Opened files C#C# : FileSystemWatcher - multiple watching folders issueFile System Watcher of Powershell on Opening a FolderC#: FileSystemWatcher only dispatches ChangedEvent
Why were the Night's Watch required to be celibate?
What happens if you do emergency landing on a US base in middle of the ocean?
What does War Machine's "Canopy! Canopy!" line mean in "Avengers: Endgame"?
Could a guilty Boris Johnson be used to cancel Brexit?
What is the right way to float a home lab?
Why was it possible to cause an Apple //e to shut down with SHIFT and paddle button 2?
Chopin: marche funèbre bar 15 impossible place
Can an old DSLR be upgraded to match modern smartphone image quality
How to make thick Asian sauces?
Can a magnetic field of a large body be stronger than its gravity?
Is it possible to kill all life on Earth?
Strange math syntax in old basic listing
Is having a hidden directory under /etc safe?
Pros and cons of writing a book review?
Can I ask a publisher for a paper that I need for reviewing
How can I grammatically understand "Wir über uns"?
Explain Ant-Man's "not it" scene from Avengers: Endgame
How can I determine the spell save DC of a monster/NPC?
What if you don't bring your credit card or debit for incidentals?
PhD student with mental health issues and bad performance
Does it cost a spell slot to cast a spell from a Ring of Spell Storing?
Asking bank to reduce APR instead of increasing credit limit
Humans meet a distant alien species. How do they standardize? - Units of Measure
Anyone teach web development? How do you assess it?
FileSystemWatcher used to watch for folder/file open
Monitor file open c# .NetFileSystemWatcher doesn't fire for Opened files C#File System Watcher of Powershell on Opening a FolderTracking files of a particular extensionWindows, Watching a folder in C#How Many Times A File's Been OpenedDetect whenever a specific file type gets openedHow to create Excel (.XLS and .XLSX) file in C# without installing Ms Office?Detecting moved files using FileSystemWatcherHow to delete all files and folders in a directory?FileSystemWatcher Changed event is raised twiceFilter FileSystemWatcher changed eventsFileSystemWatcher - 3 events during File copyFileSystemWatcher doesn't fire for Opened files C#C# : FileSystemWatcher - multiple watching folders issueFile System Watcher of Powershell on Opening a FolderC#: FileSystemWatcher only dispatches ChangedEvent
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have browsed around but cannot find any information on what I am seeking, if there is another post that already goes over this then I apologize.
I am seeking help with code that will monitor a specific folder for when the folder is opened by another person or when a file under said folder is opened. At this point I can see when a user opens and modifies any files but if they just open the file to view it, it does not throw an event even when I add LastAccessed. Any information or help would be appreciated.
Folder name is C:Junk
Code in C# 4.0:
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
public static void Run()
NotifyFilters.LastWrite
// Define the event handlers.
private static void OnChanged(object source, FileSystemEventArgs e)
// Specify what is done when a file is changed, created, or deleted.
Console.WriteLine("File: " + e.FullPath + " " + e.ChangeType);
private static void OnRenamed(object source, RenamedEventArgs e)
// Specify what is done when a file is renamed.
Console.WriteLine("File: 0 renamed to 1", e.OldFullPath, e.FullPath);
c# .net wpf filesystemwatcher
add a comment |
I have browsed around but cannot find any information on what I am seeking, if there is another post that already goes over this then I apologize.
I am seeking help with code that will monitor a specific folder for when the folder is opened by another person or when a file under said folder is opened. At this point I can see when a user opens and modifies any files but if they just open the file to view it, it does not throw an event even when I add LastAccessed. Any information or help would be appreciated.
Folder name is C:Junk
Code in C# 4.0:
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
public static void Run()
NotifyFilters.LastWrite
// Define the event handlers.
private static void OnChanged(object source, FileSystemEventArgs e)
// Specify what is done when a file is changed, created, or deleted.
Console.WriteLine("File: " + e.FullPath + " " + e.ChangeType);
private static void OnRenamed(object source, RenamedEventArgs e)
// Specify what is done when a file is renamed.
Console.WriteLine("File: 0 renamed to 1", e.OldFullPath, e.FullPath);
c# .net wpf filesystemwatcher
If folder name is C:JUNK, why don't you put it in the Path property? the Filter property is used to screen files not folders
– Steve
Feb 8 '13 at 19:12
@Steve - Per your suggestion, I changed my code but it is still not triggering on opening of folder.
– Saren
Feb 8 '13 at 19:15
1
Try filesystem filter driver to track this kind of changes. Other variants don't work well.
– Eugene Mayevski 'Allied Bits
Feb 9 '13 at 8:07
To get this done quickly, I simply relied on the NTFS security auditing layer.
– mbrownnyc
Nov 7 '13 at 16:07
add a comment |
I have browsed around but cannot find any information on what I am seeking, if there is another post that already goes over this then I apologize.
I am seeking help with code that will monitor a specific folder for when the folder is opened by another person or when a file under said folder is opened. At this point I can see when a user opens and modifies any files but if they just open the file to view it, it does not throw an event even when I add LastAccessed. Any information or help would be appreciated.
Folder name is C:Junk
Code in C# 4.0:
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
public static void Run()
NotifyFilters.LastWrite
// Define the event handlers.
private static void OnChanged(object source, FileSystemEventArgs e)
// Specify what is done when a file is changed, created, or deleted.
Console.WriteLine("File: " + e.FullPath + " " + e.ChangeType);
private static void OnRenamed(object source, RenamedEventArgs e)
// Specify what is done when a file is renamed.
Console.WriteLine("File: 0 renamed to 1", e.OldFullPath, e.FullPath);
c# .net wpf filesystemwatcher
I have browsed around but cannot find any information on what I am seeking, if there is another post that already goes over this then I apologize.
I am seeking help with code that will monitor a specific folder for when the folder is opened by another person or when a file under said folder is opened. At this point I can see when a user opens and modifies any files but if they just open the file to view it, it does not throw an event even when I add LastAccessed. Any information or help would be appreciated.
Folder name is C:Junk
Code in C# 4.0:
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
public static void Run()
NotifyFilters.LastWrite
// Define the event handlers.
private static void OnChanged(object source, FileSystemEventArgs e)
// Specify what is done when a file is changed, created, or deleted.
Console.WriteLine("File: " + e.FullPath + " " + e.ChangeType);
private static void OnRenamed(object source, RenamedEventArgs e)
// Specify what is done when a file is renamed.
Console.WriteLine("File: 0 renamed to 1", e.OldFullPath, e.FullPath);
c# .net wpf filesystemwatcher
c# .net wpf filesystemwatcher
edited Feb 8 '13 at 20:39
svick
179k40299420
179k40299420
asked Feb 8 '13 at 19:06
SarenSaren
1881413
1881413
If folder name is C:JUNK, why don't you put it in the Path property? the Filter property is used to screen files not folders
– Steve
Feb 8 '13 at 19:12
@Steve - Per your suggestion, I changed my code but it is still not triggering on opening of folder.
– Saren
Feb 8 '13 at 19:15
1
Try filesystem filter driver to track this kind of changes. Other variants don't work well.
– Eugene Mayevski 'Allied Bits
Feb 9 '13 at 8:07
To get this done quickly, I simply relied on the NTFS security auditing layer.
– mbrownnyc
Nov 7 '13 at 16:07
add a comment |
If folder name is C:JUNK, why don't you put it in the Path property? the Filter property is used to screen files not folders
– Steve
Feb 8 '13 at 19:12
@Steve - Per your suggestion, I changed my code but it is still not triggering on opening of folder.
– Saren
Feb 8 '13 at 19:15
1
Try filesystem filter driver to track this kind of changes. Other variants don't work well.
– Eugene Mayevski 'Allied Bits
Feb 9 '13 at 8:07
To get this done quickly, I simply relied on the NTFS security auditing layer.
– mbrownnyc
Nov 7 '13 at 16:07
If folder name is C:JUNK, why don't you put it in the Path property? the Filter property is used to screen files not folders
– Steve
Feb 8 '13 at 19:12
If folder name is C:JUNK, why don't you put it in the Path property? the Filter property is used to screen files not folders
– Steve
Feb 8 '13 at 19:12
@Steve - Per your suggestion, I changed my code but it is still not triggering on opening of folder.
– Saren
Feb 8 '13 at 19:15
@Steve - Per your suggestion, I changed my code but it is still not triggering on opening of folder.
– Saren
Feb 8 '13 at 19:15
1
1
Try filesystem filter driver to track this kind of changes. Other variants don't work well.
– Eugene Mayevski 'Allied Bits
Feb 9 '13 at 8:07
Try filesystem filter driver to track this kind of changes. Other variants don't work well.
– Eugene Mayevski 'Allied Bits
Feb 9 '13 at 8:07
To get this done quickly, I simply relied on the NTFS security auditing layer.
– mbrownnyc
Nov 7 '13 at 16:07
To get this done quickly, I simply relied on the NTFS security auditing layer.
– mbrownnyc
Nov 7 '13 at 16:07
add a comment |
6 Answers
6
active
oldest
votes
it does not throw an event even when I add LastAccessed.
Because NotifyFilters.LastAccessed
specifies that you wish to retreive that property, not the event to subscribe to. The available events are Changed
, Created
, or Deleted
, none of which does what you want.
You should take a look at the ReadDirectoryChangesW
Win32 function, documented here. It can be passed a FILE_NOTIFY_CHANGE_LAST_ACCESS
flag, which seems to deliver what you want:
Any change to the last access time of files in the watched directory or subtree causes a change notification wait operation to return.
Edit: disregard this, the FileSystemWatcher
does internally pass NotifyFilters.LastWrite
as int 32, which is the same as FILE_NOTIFY_CHANGE_LAST_ACCESS
, to ReadDirectoryChangesW
. That function then still does not notify on file access, I've tried.
Perhaps this is caused by this:
Last Access Time has a loose granularity that only guarantees that the time is accurate to within one hour. In Windows Vista, we've disabled updates to Last Access Time to improve NTFS performance. If you are using an application that relies on this value, you can enable it using the following command:
fsutil behavior set disablelastaccess 0
You must restart the computer for this change to take effect.
If you execute that on the command prompt, perhaps then the LastAccess
will be written and the event will fire. I'm not going to try in on my SSD and don't have a VM ready, but on Windows 7 disablelastaccess
seems to be enabled out-of-the-box.
If it still doesn't work when you disable that behavior, wait for Raymond Chen's suggestion box (or himself) to come by, usually there's a quite logical explanation for why the documentation does not seem to correctly describe the behaviour you encounter. ;-)
You may as well just scan the directory in a loop and look at the LastAccessed property of the Files. What are you trying to do when a user opens a certain file?
Thank you very much!
– Saren
Feb 8 '13 at 19:27
First try to implement it... ;)
– CodeCaster
Feb 8 '13 at 19:27
It seems to be a PITA but that's for another time, for now I am happy I have a route to take.
– Saren
Feb 8 '13 at 19:28
@Saran see edit. This won't work.
– CodeCaster
Feb 8 '13 at 20:27
add a comment |
To get On-Access file path there is one solution of minifilter driver. You have to implement minifilter driver to get the requirements implemented.
IMHO this is the correct answer
– radiolondra
Mar 23 at 13:47
add a comment |
You should set
watcher.Path = @"C:junk";
and delete watcher.Filter
line if event should fire for all files
Using Filter property you can set wildcards for matching files, for example *.txt
I have changed my Code as suggested but still no trigger on open.
– Saren
Feb 8 '13 at 19:16
add a comment |
what you really need is NtQuerySystemInformation enumeration and a timer, that way you can scan the directory and see if any of the files are open. the filesystemwatcher will not give you this info
add a comment |
public void OnChanged(object sender, FileSystemEventArgs e)
string FileName = System.IO.Path.GetFileName(e.FullPath);
if(IsAvailable(System.IO.Path.Combine(RecievedPath,FileName)))
ProcessMessage(FileName);
private void ProcessMessage(string fileName)
try
File.Copy(System.IO.Path.Combine(RecievedPath,fileName), System.IO.Path.Combine(SentPath,fileName));
MessageBox.Show("File Copied");
catch (Exception)
private static bool IsAvailable(String filePath)
try
using (FileStream inputStream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.None))
if (inputStream.Length > 0)
return true;
else
return false;
catch (Exception)
return false;
add a comment |
Digvijay Rathore gave already an answer, in my opinion the only good answer, even if a bit too short.
I want just to add a few words and a link where interested users could start.
The FileSystemWatcher is useful just to monitor what is happening inside the monitored folder, but it's not able to monitor and intercept what the user (or the OS) is doing.
For example, with a FSW (FileSystemWatcher) you can monitor when a file/folder is created, deleted, renamed or changed in some way, and those events are unleashed AFTER the action is completed, not before nor while.
A simple FSW is not able to know if the user is launching an executable from the monitored folder, in this case it will simply generate no events at all.
To catch when an executable is launched (and tons of other "events") before it is launched and make some action before the code of the executable is loaded in memory, you need to write something at lower (kernel) level, that is, you need to build a driver, in this specific case a (minifilter) File System driver.
This is a good starting point to start to understand the basic of Minifilter Windows Drivers:
https://docs.microsoft.com/en-us/windows-hardware/drivers/ifs/file-system-minifilter-drivers
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f14779616%2ffilesystemwatcher-used-to-watch-for-folder-file-open%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
it does not throw an event even when I add LastAccessed.
Because NotifyFilters.LastAccessed
specifies that you wish to retreive that property, not the event to subscribe to. The available events are Changed
, Created
, or Deleted
, none of which does what you want.
You should take a look at the ReadDirectoryChangesW
Win32 function, documented here. It can be passed a FILE_NOTIFY_CHANGE_LAST_ACCESS
flag, which seems to deliver what you want:
Any change to the last access time of files in the watched directory or subtree causes a change notification wait operation to return.
Edit: disregard this, the FileSystemWatcher
does internally pass NotifyFilters.LastWrite
as int 32, which is the same as FILE_NOTIFY_CHANGE_LAST_ACCESS
, to ReadDirectoryChangesW
. That function then still does not notify on file access, I've tried.
Perhaps this is caused by this:
Last Access Time has a loose granularity that only guarantees that the time is accurate to within one hour. In Windows Vista, we've disabled updates to Last Access Time to improve NTFS performance. If you are using an application that relies on this value, you can enable it using the following command:
fsutil behavior set disablelastaccess 0
You must restart the computer for this change to take effect.
If you execute that on the command prompt, perhaps then the LastAccess
will be written and the event will fire. I'm not going to try in on my SSD and don't have a VM ready, but on Windows 7 disablelastaccess
seems to be enabled out-of-the-box.
If it still doesn't work when you disable that behavior, wait for Raymond Chen's suggestion box (or himself) to come by, usually there's a quite logical explanation for why the documentation does not seem to correctly describe the behaviour you encounter. ;-)
You may as well just scan the directory in a loop and look at the LastAccessed property of the Files. What are you trying to do when a user opens a certain file?
Thank you very much!
– Saren
Feb 8 '13 at 19:27
First try to implement it... ;)
– CodeCaster
Feb 8 '13 at 19:27
It seems to be a PITA but that's for another time, for now I am happy I have a route to take.
– Saren
Feb 8 '13 at 19:28
@Saran see edit. This won't work.
– CodeCaster
Feb 8 '13 at 20:27
add a comment |
it does not throw an event even when I add LastAccessed.
Because NotifyFilters.LastAccessed
specifies that you wish to retreive that property, not the event to subscribe to. The available events are Changed
, Created
, or Deleted
, none of which does what you want.
You should take a look at the ReadDirectoryChangesW
Win32 function, documented here. It can be passed a FILE_NOTIFY_CHANGE_LAST_ACCESS
flag, which seems to deliver what you want:
Any change to the last access time of files in the watched directory or subtree causes a change notification wait operation to return.
Edit: disregard this, the FileSystemWatcher
does internally pass NotifyFilters.LastWrite
as int 32, which is the same as FILE_NOTIFY_CHANGE_LAST_ACCESS
, to ReadDirectoryChangesW
. That function then still does not notify on file access, I've tried.
Perhaps this is caused by this:
Last Access Time has a loose granularity that only guarantees that the time is accurate to within one hour. In Windows Vista, we've disabled updates to Last Access Time to improve NTFS performance. If you are using an application that relies on this value, you can enable it using the following command:
fsutil behavior set disablelastaccess 0
You must restart the computer for this change to take effect.
If you execute that on the command prompt, perhaps then the LastAccess
will be written and the event will fire. I'm not going to try in on my SSD and don't have a VM ready, but on Windows 7 disablelastaccess
seems to be enabled out-of-the-box.
If it still doesn't work when you disable that behavior, wait for Raymond Chen's suggestion box (or himself) to come by, usually there's a quite logical explanation for why the documentation does not seem to correctly describe the behaviour you encounter. ;-)
You may as well just scan the directory in a loop and look at the LastAccessed property of the Files. What are you trying to do when a user opens a certain file?
Thank you very much!
– Saren
Feb 8 '13 at 19:27
First try to implement it... ;)
– CodeCaster
Feb 8 '13 at 19:27
It seems to be a PITA but that's for another time, for now I am happy I have a route to take.
– Saren
Feb 8 '13 at 19:28
@Saran see edit. This won't work.
– CodeCaster
Feb 8 '13 at 20:27
add a comment |
it does not throw an event even when I add LastAccessed.
Because NotifyFilters.LastAccessed
specifies that you wish to retreive that property, not the event to subscribe to. The available events are Changed
, Created
, or Deleted
, none of which does what you want.
You should take a look at the ReadDirectoryChangesW
Win32 function, documented here. It can be passed a FILE_NOTIFY_CHANGE_LAST_ACCESS
flag, which seems to deliver what you want:
Any change to the last access time of files in the watched directory or subtree causes a change notification wait operation to return.
Edit: disregard this, the FileSystemWatcher
does internally pass NotifyFilters.LastWrite
as int 32, which is the same as FILE_NOTIFY_CHANGE_LAST_ACCESS
, to ReadDirectoryChangesW
. That function then still does not notify on file access, I've tried.
Perhaps this is caused by this:
Last Access Time has a loose granularity that only guarantees that the time is accurate to within one hour. In Windows Vista, we've disabled updates to Last Access Time to improve NTFS performance. If you are using an application that relies on this value, you can enable it using the following command:
fsutil behavior set disablelastaccess 0
You must restart the computer for this change to take effect.
If you execute that on the command prompt, perhaps then the LastAccess
will be written and the event will fire. I'm not going to try in on my SSD and don't have a VM ready, but on Windows 7 disablelastaccess
seems to be enabled out-of-the-box.
If it still doesn't work when you disable that behavior, wait for Raymond Chen's suggestion box (or himself) to come by, usually there's a quite logical explanation for why the documentation does not seem to correctly describe the behaviour you encounter. ;-)
You may as well just scan the directory in a loop and look at the LastAccessed property of the Files. What are you trying to do when a user opens a certain file?
it does not throw an event even when I add LastAccessed.
Because NotifyFilters.LastAccessed
specifies that you wish to retreive that property, not the event to subscribe to. The available events are Changed
, Created
, or Deleted
, none of which does what you want.
You should take a look at the ReadDirectoryChangesW
Win32 function, documented here. It can be passed a FILE_NOTIFY_CHANGE_LAST_ACCESS
flag, which seems to deliver what you want:
Any change to the last access time of files in the watched directory or subtree causes a change notification wait operation to return.
Edit: disregard this, the FileSystemWatcher
does internally pass NotifyFilters.LastWrite
as int 32, which is the same as FILE_NOTIFY_CHANGE_LAST_ACCESS
, to ReadDirectoryChangesW
. That function then still does not notify on file access, I've tried.
Perhaps this is caused by this:
Last Access Time has a loose granularity that only guarantees that the time is accurate to within one hour. In Windows Vista, we've disabled updates to Last Access Time to improve NTFS performance. If you are using an application that relies on this value, you can enable it using the following command:
fsutil behavior set disablelastaccess 0
You must restart the computer for this change to take effect.
If you execute that on the command prompt, perhaps then the LastAccess
will be written and the event will fire. I'm not going to try in on my SSD and don't have a VM ready, but on Windows 7 disablelastaccess
seems to be enabled out-of-the-box.
If it still doesn't work when you disable that behavior, wait for Raymond Chen's suggestion box (or himself) to come by, usually there's a quite logical explanation for why the documentation does not seem to correctly describe the behaviour you encounter. ;-)
You may as well just scan the directory in a loop and look at the LastAccessed property of the Files. What are you trying to do when a user opens a certain file?
edited Feb 8 '13 at 20:45
answered Feb 8 '13 at 19:13
CodeCasterCodeCaster
112k18153205
112k18153205
Thank you very much!
– Saren
Feb 8 '13 at 19:27
First try to implement it... ;)
– CodeCaster
Feb 8 '13 at 19:27
It seems to be a PITA but that's for another time, for now I am happy I have a route to take.
– Saren
Feb 8 '13 at 19:28
@Saran see edit. This won't work.
– CodeCaster
Feb 8 '13 at 20:27
add a comment |
Thank you very much!
– Saren
Feb 8 '13 at 19:27
First try to implement it... ;)
– CodeCaster
Feb 8 '13 at 19:27
It seems to be a PITA but that's for another time, for now I am happy I have a route to take.
– Saren
Feb 8 '13 at 19:28
@Saran see edit. This won't work.
– CodeCaster
Feb 8 '13 at 20:27
Thank you very much!
– Saren
Feb 8 '13 at 19:27
Thank you very much!
– Saren
Feb 8 '13 at 19:27
First try to implement it... ;)
– CodeCaster
Feb 8 '13 at 19:27
First try to implement it... ;)
– CodeCaster
Feb 8 '13 at 19:27
It seems to be a PITA but that's for another time, for now I am happy I have a route to take.
– Saren
Feb 8 '13 at 19:28
It seems to be a PITA but that's for another time, for now I am happy I have a route to take.
– Saren
Feb 8 '13 at 19:28
@Saran see edit. This won't work.
– CodeCaster
Feb 8 '13 at 20:27
@Saran see edit. This won't work.
– CodeCaster
Feb 8 '13 at 20:27
add a comment |
To get On-Access file path there is one solution of minifilter driver. You have to implement minifilter driver to get the requirements implemented.
IMHO this is the correct answer
– radiolondra
Mar 23 at 13:47
add a comment |
To get On-Access file path there is one solution of minifilter driver. You have to implement minifilter driver to get the requirements implemented.
IMHO this is the correct answer
– radiolondra
Mar 23 at 13:47
add a comment |
To get On-Access file path there is one solution of minifilter driver. You have to implement minifilter driver to get the requirements implemented.
To get On-Access file path there is one solution of minifilter driver. You have to implement minifilter driver to get the requirements implemented.
answered Jun 28 '17 at 9:47
Digvijay RathoreDigvijay Rathore
1338
1338
IMHO this is the correct answer
– radiolondra
Mar 23 at 13:47
add a comment |
IMHO this is the correct answer
– radiolondra
Mar 23 at 13:47
IMHO this is the correct answer
– radiolondra
Mar 23 at 13:47
IMHO this is the correct answer
– radiolondra
Mar 23 at 13:47
add a comment |
You should set
watcher.Path = @"C:junk";
and delete watcher.Filter
line if event should fire for all files
Using Filter property you can set wildcards for matching files, for example *.txt
I have changed my Code as suggested but still no trigger on open.
– Saren
Feb 8 '13 at 19:16
add a comment |
You should set
watcher.Path = @"C:junk";
and delete watcher.Filter
line if event should fire for all files
Using Filter property you can set wildcards for matching files, for example *.txt
I have changed my Code as suggested but still no trigger on open.
– Saren
Feb 8 '13 at 19:16
add a comment |
You should set
watcher.Path = @"C:junk";
and delete watcher.Filter
line if event should fire for all files
Using Filter property you can set wildcards for matching files, for example *.txt
You should set
watcher.Path = @"C:junk";
and delete watcher.Filter
line if event should fire for all files
Using Filter property you can set wildcards for matching files, for example *.txt
answered Feb 8 '13 at 19:13
VladLVladL
10.3k104976
10.3k104976
I have changed my Code as suggested but still no trigger on open.
– Saren
Feb 8 '13 at 19:16
add a comment |
I have changed my Code as suggested but still no trigger on open.
– Saren
Feb 8 '13 at 19:16
I have changed my Code as suggested but still no trigger on open.
– Saren
Feb 8 '13 at 19:16
I have changed my Code as suggested but still no trigger on open.
– Saren
Feb 8 '13 at 19:16
add a comment |
what you really need is NtQuerySystemInformation enumeration and a timer, that way you can scan the directory and see if any of the files are open. the filesystemwatcher will not give you this info
add a comment |
what you really need is NtQuerySystemInformation enumeration and a timer, that way you can scan the directory and see if any of the files are open. the filesystemwatcher will not give you this info
add a comment |
what you really need is NtQuerySystemInformation enumeration and a timer, that way you can scan the directory and see if any of the files are open. the filesystemwatcher will not give you this info
what you really need is NtQuerySystemInformation enumeration and a timer, that way you can scan the directory and see if any of the files are open. the filesystemwatcher will not give you this info
answered Feb 8 '13 at 19:50
AlexAlex
1,61311125
1,61311125
add a comment |
add a comment |
public void OnChanged(object sender, FileSystemEventArgs e)
string FileName = System.IO.Path.GetFileName(e.FullPath);
if(IsAvailable(System.IO.Path.Combine(RecievedPath,FileName)))
ProcessMessage(FileName);
private void ProcessMessage(string fileName)
try
File.Copy(System.IO.Path.Combine(RecievedPath,fileName), System.IO.Path.Combine(SentPath,fileName));
MessageBox.Show("File Copied");
catch (Exception)
private static bool IsAvailable(String filePath)
try
using (FileStream inputStream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.None))
if (inputStream.Length > 0)
return true;
else
return false;
catch (Exception)
return false;
add a comment |
public void OnChanged(object sender, FileSystemEventArgs e)
string FileName = System.IO.Path.GetFileName(e.FullPath);
if(IsAvailable(System.IO.Path.Combine(RecievedPath,FileName)))
ProcessMessage(FileName);
private void ProcessMessage(string fileName)
try
File.Copy(System.IO.Path.Combine(RecievedPath,fileName), System.IO.Path.Combine(SentPath,fileName));
MessageBox.Show("File Copied");
catch (Exception)
private static bool IsAvailable(String filePath)
try
using (FileStream inputStream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.None))
if (inputStream.Length > 0)
return true;
else
return false;
catch (Exception)
return false;
add a comment |
public void OnChanged(object sender, FileSystemEventArgs e)
string FileName = System.IO.Path.GetFileName(e.FullPath);
if(IsAvailable(System.IO.Path.Combine(RecievedPath,FileName)))
ProcessMessage(FileName);
private void ProcessMessage(string fileName)
try
File.Copy(System.IO.Path.Combine(RecievedPath,fileName), System.IO.Path.Combine(SentPath,fileName));
MessageBox.Show("File Copied");
catch (Exception)
private static bool IsAvailable(String filePath)
try
using (FileStream inputStream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.None))
if (inputStream.Length > 0)
return true;
else
return false;
catch (Exception)
return false;
public void OnChanged(object sender, FileSystemEventArgs e)
string FileName = System.IO.Path.GetFileName(e.FullPath);
if(IsAvailable(System.IO.Path.Combine(RecievedPath,FileName)))
ProcessMessage(FileName);
private void ProcessMessage(string fileName)
try
File.Copy(System.IO.Path.Combine(RecievedPath,fileName), System.IO.Path.Combine(SentPath,fileName));
MessageBox.Show("File Copied");
catch (Exception)
private static bool IsAvailable(String filePath)
try
using (FileStream inputStream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.None))
if (inputStream.Length > 0)
return true;
else
return false;
catch (Exception)
return false;
edited Oct 14 '16 at 9:02
Tunaki
93.7k23210292
93.7k23210292
answered Oct 14 '16 at 9:01
Ajay KumarAjay Kumar
13
13
add a comment |
add a comment |
Digvijay Rathore gave already an answer, in my opinion the only good answer, even if a bit too short.
I want just to add a few words and a link where interested users could start.
The FileSystemWatcher is useful just to monitor what is happening inside the monitored folder, but it's not able to monitor and intercept what the user (or the OS) is doing.
For example, with a FSW (FileSystemWatcher) you can monitor when a file/folder is created, deleted, renamed or changed in some way, and those events are unleashed AFTER the action is completed, not before nor while.
A simple FSW is not able to know if the user is launching an executable from the monitored folder, in this case it will simply generate no events at all.
To catch when an executable is launched (and tons of other "events") before it is launched and make some action before the code of the executable is loaded in memory, you need to write something at lower (kernel) level, that is, you need to build a driver, in this specific case a (minifilter) File System driver.
This is a good starting point to start to understand the basic of Minifilter Windows Drivers:
https://docs.microsoft.com/en-us/windows-hardware/drivers/ifs/file-system-minifilter-drivers
add a comment |
Digvijay Rathore gave already an answer, in my opinion the only good answer, even if a bit too short.
I want just to add a few words and a link where interested users could start.
The FileSystemWatcher is useful just to monitor what is happening inside the monitored folder, but it's not able to monitor and intercept what the user (or the OS) is doing.
For example, with a FSW (FileSystemWatcher) you can monitor when a file/folder is created, deleted, renamed or changed in some way, and those events are unleashed AFTER the action is completed, not before nor while.
A simple FSW is not able to know if the user is launching an executable from the monitored folder, in this case it will simply generate no events at all.
To catch when an executable is launched (and tons of other "events") before it is launched and make some action before the code of the executable is loaded in memory, you need to write something at lower (kernel) level, that is, you need to build a driver, in this specific case a (minifilter) File System driver.
This is a good starting point to start to understand the basic of Minifilter Windows Drivers:
https://docs.microsoft.com/en-us/windows-hardware/drivers/ifs/file-system-minifilter-drivers
add a comment |
Digvijay Rathore gave already an answer, in my opinion the only good answer, even if a bit too short.
I want just to add a few words and a link where interested users could start.
The FileSystemWatcher is useful just to monitor what is happening inside the monitored folder, but it's not able to monitor and intercept what the user (or the OS) is doing.
For example, with a FSW (FileSystemWatcher) you can monitor when a file/folder is created, deleted, renamed or changed in some way, and those events are unleashed AFTER the action is completed, not before nor while.
A simple FSW is not able to know if the user is launching an executable from the monitored folder, in this case it will simply generate no events at all.
To catch when an executable is launched (and tons of other "events") before it is launched and make some action before the code of the executable is loaded in memory, you need to write something at lower (kernel) level, that is, you need to build a driver, in this specific case a (minifilter) File System driver.
This is a good starting point to start to understand the basic of Minifilter Windows Drivers:
https://docs.microsoft.com/en-us/windows-hardware/drivers/ifs/file-system-minifilter-drivers
Digvijay Rathore gave already an answer, in my opinion the only good answer, even if a bit too short.
I want just to add a few words and a link where interested users could start.
The FileSystemWatcher is useful just to monitor what is happening inside the monitored folder, but it's not able to monitor and intercept what the user (or the OS) is doing.
For example, with a FSW (FileSystemWatcher) you can monitor when a file/folder is created, deleted, renamed or changed in some way, and those events are unleashed AFTER the action is completed, not before nor while.
A simple FSW is not able to know if the user is launching an executable from the monitored folder, in this case it will simply generate no events at all.
To catch when an executable is launched (and tons of other "events") before it is launched and make some action before the code of the executable is loaded in memory, you need to write something at lower (kernel) level, that is, you need to build a driver, in this specific case a (minifilter) File System driver.
This is a good starting point to start to understand the basic of Minifilter Windows Drivers:
https://docs.microsoft.com/en-us/windows-hardware/drivers/ifs/file-system-minifilter-drivers
answered Mar 24 at 12:23
radiolondraradiolondra
7318
7318
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f14779616%2ffilesystemwatcher-used-to-watch-for-folder-file-open%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
If folder name is C:JUNK, why don't you put it in the Path property? the Filter property is used to screen files not folders
– Steve
Feb 8 '13 at 19:12
@Steve - Per your suggestion, I changed my code but it is still not triggering on opening of folder.
– Saren
Feb 8 '13 at 19:15
1
Try filesystem filter driver to track this kind of changes. Other variants don't work well.
– Eugene Mayevski 'Allied Bits
Feb 9 '13 at 8:07
To get this done quickly, I simply relied on the NTFS security auditing layer.
– mbrownnyc
Nov 7 '13 at 16:07