Create Folder Share on Remote Computer

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dave

    #1

    Create Folder Share on Remote Computer

    I have an application where I am providing the user the ability to
    select or create a folder on a domain, using SHBrowseForFold er. 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.
  • Veign

    #2
    Re: Create Folder Share on Remote Computer

    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
    Your #1 source for using API-functions in Visual Basic and classes for the .NET runtime!


    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


    ACC: How to Return an UNC Path from an Existing Drive Letter


    --
    Chris Hanscom
    MVP (Visual Basic)
    Veign. Отметки "Нравится": 116. Veign helps people step into the future with confidence. We teach powerful tech skills in a practical, approachable way — giving you the tools to build, create, and...

    --

    "Dave" <dmon_57@yahoo. com> wrote in message
    news:6c9a4d6c.0 404141145.3a378 dd5@posting.goo gle.com...[color=blue]
    > I have an application where I am providing the user the ability to
    > select or create a folder on a domain, using SHBrowseForFold er. 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.[/color]


    Comment

    • Jeff Johnson [MVP: VB]

      #3
      Re: Create Folder Share on Remote Computer


      "Dave" <dmon_57@yahoo. com> wrote in message
      news:6c9a4d6c.0 404141145.3a378 dd5@posting.goo gle.com...
      [color=blue]
      > I have an application where I am providing the user the ability to
      > select or create a folder on a domain, using SHBrowseForFold er. 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?[/color]

      Creating a folder and creating a share are two different things. What
      exactly are you trying to do?


      Comment

      • Randy Birch

        #4
        Re: Create Folder Share on Remote Computer

        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
        VBnet provides Intermediate and Advanced Win32 API code for VB developers. Comprehensive Code, FAQ, Developers Resources & News, alphabetical API/Type/Constant/Method Index, along with the largest Visual Basic-related links list on the net.


        --

        Randy Birch
        MVP Visual Basic

        Please respond only to the newsgroups so all can benefit.


        "Dave" <dmon_57@yahoo. com> wrote in message
        news:6c9a4d6c.0 404141145.3a378 dd5@posting.goo gle.com...
        : I have an application where I am providing the user the ability to
        : select or create a folder on a domain, using SHBrowseForFold er. 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.

        Comment

        • Björn Holmgren

          #5
          Re: Create Folder Share on Remote Computer

          "Dave" <dmon_57@yahoo. com> wrote in message
          news:6c9a4d6c.0 404141145.3a378 dd5@posting.goo gle.com...[color=blue]
          > I have an application where I am providing the user the ability to
          > select or create a folder on a domain, using SHBrowseForFold er. 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.[/color]

          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 NetAPIBufferFre e Lib "netapi32.d ll" _
          Alias "NetApiBufferFr ee" (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(sU NCPath 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(TempSt r.XLo, Buf + 24, 2)
          Result = PtrToInt(TempSt r.XHi, Buf + 26, 2)
          LSet TempPtr = TempStr
          Result = PtrToStr(STRArr ay(0), TempPtr.x)
          sBasePath = Left(STRArray, StrLen(TempPtr. x))

          Result = NetAPIBufferFre e(Buf)

          Server = sServer
          GetLocalPath = sBasePath & sTemp
          End If
          End Function

          '----------

          --
          Björn Holmgren
          Guide Konsult AB


          Comment

          Working...