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;








6















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);










share|improve this question
























  • 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

















6















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);










share|improve this question
























  • 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













6












6








6


3






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);










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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

















  • 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












6 Answers
6






active

oldest

votes


















2















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?






share|improve this answer

























  • 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


















1














To get On-Access file path there is one solution of minifilter driver. You have to implement minifilter driver to get the requirements implemented.






share|improve this answer























  • IMHO this is the correct answer

    – radiolondra
    Mar 23 at 13:47


















0














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






share|improve this answer























  • I have changed my Code as suggested but still no trigger on open.

    – Saren
    Feb 8 '13 at 19:16


















0














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






share|improve this answer






























    0














    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;







    share|improve this answer
































      0














      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






      share|improve this answer























        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
        );



        );













        draft saved

        draft discarded


















        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









        2















        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?






        share|improve this answer

























        • 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















        2















        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?






        share|improve this answer

























        • 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













        2












        2








        2








        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?






        share|improve this answer
















        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?







        share|improve this answer














        share|improve this answer



        share|improve this answer








        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

















        • 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













        1














        To get On-Access file path there is one solution of minifilter driver. You have to implement minifilter driver to get the requirements implemented.






        share|improve this answer























        • IMHO this is the correct answer

          – radiolondra
          Mar 23 at 13:47















        1














        To get On-Access file path there is one solution of minifilter driver. You have to implement minifilter driver to get the requirements implemented.






        share|improve this answer























        • IMHO this is the correct answer

          – radiolondra
          Mar 23 at 13:47













        1












        1








        1







        To get On-Access file path there is one solution of minifilter driver. You have to implement minifilter driver to get the requirements implemented.






        share|improve this answer













        To get On-Access file path there is one solution of minifilter driver. You have to implement minifilter driver to get the requirements implemented.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jun 28 '17 at 9:47









        Digvijay RathoreDigvijay Rathore

        1338




        1338












        • 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





        IMHO this is the correct answer

        – radiolondra
        Mar 23 at 13:47











        0














        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






        share|improve this answer























        • I have changed my Code as suggested but still no trigger on open.

          – Saren
          Feb 8 '13 at 19:16















        0














        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






        share|improve this answer























        • I have changed my Code as suggested but still no trigger on open.

          – Saren
          Feb 8 '13 at 19:16













        0












        0








        0







        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






        share|improve this answer













        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







        share|improve this answer












        share|improve this answer



        share|improve this answer










        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

















        • 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











        0














        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






        share|improve this answer



























          0














          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






          share|improve this answer

























            0












            0








            0







            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






            share|improve this answer













            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







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Feb 8 '13 at 19:50









            AlexAlex

            1,61311125




            1,61311125





















                0














                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;







                share|improve this answer





























                  0














                  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;







                  share|improve this answer



























                    0












                    0








                    0







                    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;







                    share|improve this answer















                    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;








                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Oct 14 '16 at 9:02









                    Tunaki

                    93.7k23210292




                    93.7k23210292










                    answered Oct 14 '16 at 9:01









                    Ajay KumarAjay Kumar

                    13




                    13





















                        0














                        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






                        share|improve this answer



























                          0














                          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






                          share|improve this answer

























                            0












                            0








                            0







                            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






                            share|improve this answer













                            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







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Mar 24 at 12:23









                            radiolondraradiolondra

                            7318




                            7318



























                                draft saved

                                draft discarded
















































                                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.




                                draft saved


                                draft discarded














                                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





















































                                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







                                Popular posts from this blog

                                Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                                SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                                은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현