Visual Studio 2010 - determine remote share/path in use

Posted on 2012-09-21
Last Modified: 2012-12-18
I have a console app I'm working on where I retrieve a remote share/path.
Whether the user data on that server is a share, or not, I want to determine if the user is using the data.
In the case of a share, the path would be \\server\userID$
In the other instance, the user would be setup on folder redirection, and their data path would be \\server\frdata$\userID (share would be frdata$, but the userID would not be a share, simply a subfolder in the share).

I think I can perform the logic for the above, but I need to know how I would determine if the parent folder (or anything therein) is in use.  Locally on the console, I would bring up fsmgmt.msc and check the Open Files listings for that path...

I found vbscript code (, but wanted to know if there was anything suited for that I could use instead...?
Question by:sirbounty
    LVL 1

    Accepted Solution

    Folders dont have any real state on if they are in use or not. If a file in the folder is in use, then the folder can't be moved, renamed, or deleted..

    Public Function FileInUse(ByVal sFile As String) As Boolean 
     Dim thisFileInUse As Boolean = False 
     If System.IO.File.Exists(sFile) Then 
           Using f As New IO.FileStream(sFile, FileMode.Open, FileAccess.ReadWrite, FileShare.None) 
                    ' thisFileInUse = False 
           End Using 
           thisFileInUse = True 
         End Try 
     End If 
     Return thisFileInUse 
    End Function 

    Open in new window

    Just a note though, some applications like Notepad only have the file open for a limited amount of time.  Notepad actually just opens the file and dumps the text into memory.
    LVL 67

    Author Comment

    Surely there's a way to get at that list of open files and just filter out any that have the user's path in there?
    I can view it in the Shared Folders applet, so it's being stored somewhere, I would think...?

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    In my previous two articles we discussed Binary Serialization ( and XML Serialization ( In this article we will try to know more about SOAP (Simple Object Acces…
    The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now