server\share values  -- Urgent

Posted on 2006-04-13
Last Modified: 2010-04-23

I have people that say that this can be done. have tried a number of things with no success.


the only thing that I know is that there is a folder named testfolder and a file named test.txt.

Is there anyway to get the two unknown values above?

Question by:earngreen
    LVL 1

    Accepted Solution


    If the folders are published in Active Directory, you can programitically use the code on this page to search for them

    Or, (also if the folders are published in Active Directory), you can just search for them in AD Users and Computers by right clicking on domain, choose "find", then select "Shared Folders" in the Find drop down box.

    IF they are NOT published, you may be stuck with, at a minimum, doing a 'for each' search on every server\share in the domain. This code can at least get you started by
    '--Insert a For each loop here For every computer in domain
    strComputer = ""
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

    Set colShares = objWMIService.ExecQuery("Select * from Win32_Share")

    StrConCat = "."

    For each objShare in colShares
        'Instead of concatenating these to print them, you'd do a search here.
        StrConCat = StrConCat  &  "Name: " & objShare.Name     & VbTab & VbTab & VbTab
        StrConCat = StrConCat  &  "Path: " & objShare.Path     & VbCrLF
    wscript.echo strConCat

    Author Comment

    Sorry that will not work because then I will have to store VBS file with every app. I need something in pure
    LVL 96

    Expert Comment

    by:Bob Learned
    Are you trying to find the server name and share name for a file path?


    Author Comment

    Yes Bob

    Really having a hard time with this one. I am currently working on a couple of things that i found out on the net but never attempted to do anything like this so am a little nervous about what I am going to do.

    I found this which will return the network drives on the computer but I need to limit to one or two to search. having trouble with creating an array to store the drives. Then I could convert to a string and concatenate and filter as I would like.

    I also found this

    Don't know anything about VB6 trying to pass the filename as a parameter to the class and see what happens.

    Any suggestions on how to find server name and share name and concatenate the file path?

    LVL 96

    Expert Comment

    by:Bob Learned
    I am still trying to figure out, though, if you have the full UNC name, or just a file name, without knowing the server name?  Or, do you want to search through mapped networks drives for that file path?


    Author Comment

    I do not have the full UNC name. This is the problem.

    For instance,

    this part is known


    and this part is unknown


    Ideally I would like to get the server name and sharepath.

    Author Comment


    I created this from the Code on this page using the fGetUNCPath function from  I am trying to store all the drives in array but having trouble with the array. I then will store the items in an array and concatenate the path. Then I want to check to see if the file exists, if so then complete the operation. If not return a message that says file not found.

    The array below does not display properly. Not sure what the issue is. I also tried to
    TotalUNCPath = ShowArray to return the array for display in a Sub but returned no values.

    Any ideas?

    Dim strAllDrives As String
            Dim strTmp As String
            Dim strTemp As String
            Dim StrReturnDrives As String
            Dim SfileName As String
            Dim UNCPath As String
            Dim i As Integer
            Dim UniversalPath As String

            strAllDrives = fGetDrives()
            If strAllDrives <> "" Then
                    strTmp = Mid(strAllDrives, 1, InStr(strAllDrives, vbNullChar) - 1)
                    'strTmp = Mid(strAllDrives, 1, InStr(strAllDrives, vbNullChar) + 1)
                    strAllDrives = Mid(strAllDrives, InStr(strAllDrives, vbNullChar) + 1)

                    Select Case fDriveType(strTmp)

                        Case "Network Drive"

                         UniversalPath = ((fGetUNCPath(Microsoft.VisualBasic.Left(strTmp, Len(strTmp) - 1).ToString)))

                            SfileName = UniversalPath
                            Dim ShowArray As String
                            Dim strArray(Len(SfileName)) As String
                            For i = 1 To Len(SfileName)
                                strArray(i) = strArray(i) & Mid(SfileName, i, 1)
                                ShowArray = strArray(i)
                    End Select

             Loop While strAllDrives <> ""

            End If

        End Function
    LVL 96

    Expert Comment

    by:Bob Learned
    No ideas.


    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Article by: Kraeven
    Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    733 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

    23 Experts available now in Live!

    Get 1:1 Help Now