vb.net how to check network drive is mapped

Viewed 31

I am studying VB.NET and looking for way to check if application mapped to network drive. I check vb.net how to check if a network drive is mapped persistently

and i also trying to ping to network drive. However, this method seem not workinng.

I was trying ping to network drive and it was always return false.

I made function. On the function part

    Public Function CheckForInternetConnection(path As String) As Boolean
        Try
            Using client = New WebClient()

                Using stream = client.OpenRead(path)
                    Return True
                End Using
            End Using
        Catch
            Return False
        End Try
    End Function

On the running part i call this function above

CheckForInternetConnection("google.com")
CheckForInternetConnection("\\mynetowrk_Driver.com\system\application")

When i use CheckForInternetConnection with "google.com" it return "TRUE" However, when i use "\mynetowrk_Driver.com\system\application" this network drive, it return FALSE

I am not sure how i can check if netowork driver was mapped .

1 Answers

If I understand correctly, you are trying to validate two different things. See if the code below helps you:

Public Function CheckForInternetConnection(path As String) As Boolean
    Try
        Return My.Computer.Network.Ping(path)
    Catch pingException As System.Net.NetworkInformation.PingException
        Return IO.Directory.Exists(path)
    Catch ex As Exception
        Return False
    End Try
End Function
Related