Tech Off Thread

5 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Who has a handle on a network file?

Back to Forum: Tech Off
  • User profile image
    phreaks

    Is there a way to determine who has a handle on an open file on a network share in C#?

    I have an app that creates some reports out on a network share, if someone has one of the reports open, I need to know.

    Being able to determine who has the file open would be benifical.

  • User profile image
    W3bbo

    phreaks wrote:
    Is there a way to determine who has a handle on an open file on a network share in C#?

    I have an app that creates some reports out on a network share, if someone has one of the reports open, I need to know.

    Being able to determine who has the file open would be benifical.


    It's possible, sure. Take a look at fsmgmt.msc, it shows the Usernames of who has what file open. My bet is some function requiring P/Invoke.

  • User profile image
    phreaks

    W3bbo wrote:
    
    phreaks wrote: Is there a way to determine who has a handle on an open file on a network share in C#?

    I have an app that creates some reports out on a network share, if someone has one of the reports open, I need to know.

    Being able to determine who has the file open would be benifical.


    It's possible, sure. Take a look at fsmgmt.msc, it shows the Usernames of who has what file open. My bet is some function requiring P/Invoke.


    Ya, you can also use OpenFiles.exe located in %System32%.
    I *could* load that executable and query the results but I would rather implement a solution in Code (API or managed) if possible.

    OpenFiles /Query /s <serverName>


    Been looking for an API that would facilitate this, but am coming up empty handed.

  • User profile image
    pacman31

    CheckOut NetFileEnum, OpenFiles.exe links to this function and it appears to provide the information you need.



  • User profile image
    phreaks

    pacman31 wrote:
    CheckOut NetFileEnum, OpenFiles.exe links to this function and it appears to provide the information you need.





    I always have loved pacman. Wink

    Thank you!

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/netmgmt/netmgmt/netfileenum_sample_windows_95_98_me_.asp

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.