How to get UNC path from a mapped network share drive

Just starting out? Need help? Post your questions and find answers here.
delta69
User
User
Posts: 15
Joined: Fri Apr 25, 2003 10:56 pm

How to get UNC path from a mapped network share drive

Post by delta69 »

Hello,

Could someone tell me how get the UNC path from a mapped network share's drive letter ?

If I have a mapped drive called X:\, connected to \\myserver\share, I'd like to get "\\myserver\share" when giving "X:\" as parameter.

Thanks for your help !

Regards,
Delta69
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

I wanted to try this but it seems that the API function WNetGetConnection_ is not implemented in Purebasic 3.62

Code: Select all

  For count = 4 To 26
    szDrivLettr.s = Chr(count + 64) + ":"
    DriveType = GetDriveType_(szDrivLettr)
    If DriveType = #DRIVE_REMOTE
      WNetGetConnection_(szDrivLettr.s, szShare.s, 64)
      result.s = result + szDrivLettr + szShare + Chr(13) + Chr(10)
    End If
  Next
  If Len(result)
    MessageRequester("", result,0)
  End If
Insomniac
New User
New User
Posts: 6
Joined: Sun Apr 27, 2003 12:28 am
Location: New Zealand

Post by Insomniac »

did you forget to search :(

Rings published an example here

viewtopic.php?t=6102

Regards

Insomniac
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

I only searched with keyword 'UNC'.
Sorry

This works ; thanks !

Code: Select all

#dllMPR = 1
If OpenLibrary(#dllMPR,"MPR.DLL") 
 For count.b = 4 To 26
  DriveLetter.s = Chr(count + 64) + ":"
  DriveType.l = GetDriveType_(DriveLetter)
   If DriveType = #DRIVE_REMOTE
    UNCPath.s = Space(128) : LenUNCPath.l = 127
    dummy.l = CallFunction(#dllMPR,"WNetGetConnectionA",@DriveLetter,@UNCPath,@LenUNCPath) 
    If dummy = #NO_ERROR
     UNCPath = Left(UNCPath,LenUNCPath)
    Else
     Select dummy
     Case #ERROR_BAD_DEVICE
      UNCPath = "ERROR_BAD_DEVICE"
     Case #ERROR_NOT_CONNECTED
      UNCPath = "ERROR_NOT_CONNECTED"
     Case #ERROR_MORE_DATA
      UNCPath = "ERROR_MORE_DATA"
     Case #ERROR_CONNECTION_UNAVAIL
      UNCPath = "ERROR_CONNECTION_UNAVAIL"
     Case #ERROR_NO_NETWORK
      UNCPath = "ERROR_NO_NETWORK"
     Case #ERROR_EXTENDED_ERROR 
      UNCPath = "ERROR_EXTENDED_ERROR"
     Case #ERROR_NO_NET_OR_BAD_PATH
      UNCPath = "ERROR_NO_NET_OR_BAD_PATH"
     Case #ERROR_INVALID_ADDRESS
      UNCPath = "ERROR_INVALID_ADDRESS"
     Default
      UNCPath = "UNKNOWN ERROR " + Str(dummy)
     EndSelect
    EndIf
    result.s = result + DriveLetter + " -> '" + UNCPath + "' " + Str(LenUNCPath) +Chr(13) + Chr(10)
  EndIf
 Next
 If Len(result)
  MessageRequester("UNC", result,0)
 EndIf
Else
 MessageRequester("Info","MPR.DLL not found",0) 
EndIf
Post Reply