"Dave" <dm*****@yahoo.com> wrote in message
news:6c**************************@posting.google.c om...
I have an application where I am providing the user the ability to
select or create a folder on a domain, using SHBrowseForFolder. When
the user selects/creates a folder on a remote computer, it returns the
UNC path of that folder.
Using ADSI IADsFileShare, I would like to create that share, but the
.Path property seems to reject the UNC. Is there a way of converting
that UNC to the logical drive path or some other way of setting the
path in order to Set the Share?
Much Thanks.
Just pass the UNC path to the GetLocalPath function (below) and it will
return the server local path.
'----------
Private Type MungeLong
x As Long
Dummy As Integer
End Type
Private Type MungeInt
XLo As Integer
XHi As Integer
Dummy As Integer
End Type
Private Declare Function NetShareGetInfo Lib "NETAPI32" _
(ByRef ServerName As Byte, _
ByRef NetName As Byte, _
ByVal Level As Long, _
ByRef buffer As Long) As Long
Private Declare Function NetAPIBufferFree Lib "netapi32.dll" _
Alias "NetApiBufferFree" (bufptr As Any) As Long
Private Declare Function PtrToInt Lib "kernel32" Alias "lstrcpynW" _
(RetVal As Any, ByVal Ptr As Long, _
ByVal nCharCount As Long) As Long
Private Declare Function PtrToStr Lib "kernel32" Alias "lstrcpyW" _
(RetVal As Byte, ByVal Ptr As Long) As Long
Private Declare Function StrLen Lib "kernel32" Alias "lstrlenW" _
(ByVal Ptr As Long) As Long
Public Function GetLocalPath(sUNCPath As String) As String
Dim sTemp As String
Dim sServer As String
Dim sShare As String
Dim baServer() As Byte
Dim baShare() As Byte
Dim Result As Long
Dim Buf As Long
Dim TempStr As MungeInt
Dim TempPtr As MungeLong
Dim STRArray(0 To 255) As Byte
Dim sBasePath As String
sTemp = Mid(sUNCPath, 3)
sServer = Left(sTemp, InStr(1, sTemp, "\") - 1)
sTemp = Mid(sTemp, InStr(1, sTemp, "\") + 1)
If InStr(1, sTemp, "\") > 0 Then
sShare = Left(sTemp, InStr(1, sTemp, "\") - 1)
sTemp = Mid(sTemp, InStr(1, sTemp, "\"))
Else
sShare = sTemp
sTemp = ""
End If
baServer = "\\" & sServer & Chr(0)
baShare = UCase(sShare) & Chr(0)
Result = NetShareGetInfo(baServer(0), baShare(0), 2, Buf)
mvarLastError = Result
If Result = 0 Then
Result = PtrToInt(TempStr.XLo, Buf + 24, 2)
Result = PtrToInt(TempStr.XHi, Buf + 26, 2)
LSet TempPtr = TempStr
Result = PtrToStr(STRArray(0), TempPtr.x)
sBasePath = Left(STRArray, StrLen(TempPtr.x))
Result = NetAPIBufferFree(Buf)
Server = sServer
GetLocalPath = sBasePath & sTemp
End If
End Function
'----------
--
Björn Holmgren
Guide Konsult AB