Project Updated - Version 1.4
Code:' Changelog: ' Version 1.4 (Released 25 Apr 2024) ' -The .Drive legacy method now returns the same path for ' mapped network drives. ' -There's now a drive icon and control name/version in the ' combobox during design mode instead of a generic combo.
Download from GitHub
I went with just Ambient.DisplayName for the IDE (with icon); so it will say e.g. "ucDriveCombo1"
So for network paths, I stuck pretty closely to the proposed version earlier for WNetGetUniversalNameW; I don't know why it wasn't working. I put a mapped drive on a VM, and confirmed it's working now.
Here's what I wound up doing:
If something isn't right let me know.Code:Private Sub SetOldName(sPath As String, sLetter As String, nIdx As Long) Dim sTmp As String Dim sOld As String Dim dwFlag As Long sOld = LCase$(sLetter) & ":" If PathIsNetworkPathW(StrPtr(sPath)) Then sOld = GetOldNetName(sOld) Else sTmp = String$(34, 0) If GetVolumeInformationW(StrPtr(sPath), StrPtr(sTmp), 34, ByVal 0, 0, dwFlag, 0, 0) Then If InStr(sTmp, vbNullChar) > 1 Then sTmp = Left$(sTmp, InStr(sTmp, vbNullChar) - 1) sOld = sOld & " [" & sTmp & "]" End If End If End If mDrives(nIdx).NameOld = sOld End Sub Private Function GetOldNetName(ByVal sLetter As String) As String Dim tn As UNIVERSAL_NAME_INFOW Dim lRet As Long Dim bt() As Byte Dim cb As Long ReDim bt((MAX_PATH * 2 + 1) + LenB(tn)) cb = UBound(bt) + 1 lRet = WNetGetUniversalNameW(StrPtr(sLetter), UNIVERSAL_NAME_INFO_LEVEL, bt(0), cb) If lRet = S_OK Then CopyMemory tn, bt(0), LenB(tn) Dim sPath As String Dim cch As Long cch = lstrlenW(ByVal tn.lpUniversalName) If cch = 0 Then GetOldNetName = sLetter Exit Function End If sPath = String$(cch, 0) CopyMemory ByVal StrPtr(sPath), ByVal tn.lpUniversalName, cch * 2 GetOldNetName = sLetter & " [" & sPath & "]" Exit Function Else Debug.Print "GetOldNetName->Error: " & lRet End If GetOldNetName = sLetter End Function




Reply With Quote
