By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,556 Members | 1,100 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,556 IT Pros & Developers. It's quick & easy.

Create Folder Share on Remote Computer

P: n/a
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.
Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Something to check out is the NetShareGetInfo API: - No environment where I
currently am to test, but check it out seems promising...

NetShareGetInfo with Sample
http://www.mentalis.org/apilist/NetShareGetInfo.shtml

NetShareGetInfo on MSDN
http://msdn.microsoft.com/library/de...aregetinfo.asp

<---Going the other way--->

HOWTO: Get UNC Path From a Mapped Network Share's Drive Letter
http://support.microsoft.com/default...NoWebContent=1

ACC: How to Return an UNC Path from an Existing Drive Letter
http://support.microsoft.com/default...NoWebContent=1

--
Chris Hanscom
MVP (Visual Basic)
http://www.veign.com
--

"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.

Jul 17 '05 #2

P: n/a

"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?


Creating a folder and creating a share are two different things. What
exactly are you trying to do?
Jul 17 '05 #3

P: n/a
As Jeff said, creating folders and sharing are different beasts. The code to
actually create a share on a local or remote machine can be found at
http://vbnet.mvps.org/code/network/netshareadd.htm

--

Randy Birch
MVP Visual Basic
http://vbnet.mvps.org/
Please respond only to the newsgroups so all can benefit.
"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.

Jul 17 '05 #4

P: n/a
"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
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.