ネットワークドライブの参照先の取得




Option Explicit

Private Declare Function WNetGetUniversalName Lib "mpr" Alias "WNetGetUniversalNameA" ( _
    ByVal lpLocalPath As String, _
    ByVal dwInfoLevel As Long, _
    lpBuffer As Any, _
    lpBufferSize As Long _
) As Long

Private Type UNIVERSAL_NAME_INFO
    lpUniversalName As String * 1024
End Type

Public Function GetUniversalName(sFilePath As String) As String
    Dim sBuf As UNIVERSAL_NAME_INFO
    Dim nSize As Long
    Dim I As Long
    Dim sName As String
    
    GetUniversalName = ""
    
    Call WNetGetUniversalName(sFilePath, 1, 0, nSize)
    Call WNetGetUniversalName(sFilePath, 1, sBuf, nSize)
    
    sName = sBuf.lpUniversalName
    sName = Mid$(sName, InStr(sName, Chr(0)) + 1)
    sName = Left$(sName, InStr(sName, Chr(0)) - 1)

    GetUniversalName = sName
End Function