Japskunk72
Programmer
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
Thanks
JT
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
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
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)