Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detect Physical Drives & Map Drives

Status
Not open for further replies.

Japskunk72

Programmer
Feb 19, 2003
64
US
How do I get a list of all the physical drives on a computer? Is there also a way to detect map drives and when a drive letter is a mapping? and how do you get that UNC path?
Thanks
JT
 
this function does the unc. I found it on the internet. can't remember where.


Code:
Private Declare Ansi Function WNetGetConnection Lib "mpr.dll" Alias "WNetGetConnectionA" (ByVal lpszLocalName As String, ByVal lpszRemoteName As System.Text.StringBuilder, ByRef cbRemoteName As Int32) As Int32
Public Shared Function PathtoUNC(ByVal strpath As String) As String
            On Error GoTo errortrap

            Dim sbUNCName As New System.Text.StringBuilder(300)
            Dim UNCPath As String
            Dim iCapacity As Long = sbUNCName.Capacity

            If strpath.Substring(0, 1).ToUpper > "E" And strpath.Substring(0, 1).ToUpper <= "Z" Then
                WNetGetConnection(strpath.Substring(0, 2), sbUNCName, iCapacity)
                UNCPath = Path.Combine(sbUNCName.ToString.TrimStart, strpath.Substring(3)).ToString()
                Return UNCPath
            Else
                Return strpath
            End If

            Exit Function

errortrap:
            Resume Next
        End Function

and this is to get the logicaldrives. look at the properties for fsdrive to determine wether its a share or not.

Code:
Dim fs As New FileSystemObject
        Dim fsdrives As Scripting.Drives
        Dim fsdrive As Scripting.Drive
        fsdrives = fs.Drives
        For Each fsdrive In fsdrives
            If Not fsdrive.ShareName Is Nothing Then
                ComboBox1.Items.Add(fsdrive.DriveLetter & ":\ " & " " & fsdrive.ShareName)
            Else
                ComboBox1.Items.Add(fsdrive.DriveLetter & ":\ ")
            End If
        Next
        Marshal.ReleaseComObject(fsdrive)
        Marshal.ReleaseComObject(fsdrives)
        Marshal.ReleaseComObject(fs)

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top