Solved

Share a folder in VB

Posted on 1998-05-20
3
785 Views
Last Modified: 2008-02-01
How can I programmatically share a folder, including rights and password, from VB?
0
Comment
Question by:ianders
3 Comments
 
LVL 2

Expert Comment

by:woka
ID: 1456378
This question is for Yowkee to get his points.  Please don't submit an answer unless that's you.
0
 
LVL 4

Accepted Solution

by:
yowkee earned 100 total points
ID: 1456379
Thanks woka. :)
I post the code once again.

'=====General Declaration======
Private Type Share_Info_50
    shi50_netname As String * 13
    shi50_type As Byte
    shi50_flags As Integer
    shi50_remark As String
    shi50_path As String
    shi50_rw_pssword As String * 9
    shi50_ro_password As String * 9
End Type

Public Const SHI50F_RDONLY = &H1
Public Const SHI50F_FULL = &H2
Public Const SHI50F_DEPENDSON = SHI50F_RDONLY Or SHI50F_FULL
Public Const SHI50F_ACCESSMASK = SHI50F_RDONLY Or SHI50F_FULL
Public Const SHI50F_PERSIST = &H100
Public Const SHI50F_SYSTEM = &H200
Public Const STYPE_DISKTREE = 0
Public Const SHI_USES_UNLIMITED = 31

Private Declare Function NetShareAdd Lib "Svrapi.dll" _
    (ByVal Server As String, _
     ByVal Level As Long, _
     si As Share_Info_50, _
     ByVal Length As Long) As Long

'======Function to share directory========
Public Function Share(ByVal lpShareName As String, _
                      ByVal lpPath As String, _
                      ByVal lpRemark As String, _
                      ByVal lpPassword As String) As Long
                                   
   Dim lRtn As Long
   Dim lLen as Long
   Dim si50 As Share_Info_50
   
   si50.shi50_netname = lpShareName + vbNullChar
   si50.shi50_type = STYPE_DISKTREE
   si50.shi50_remark = lpRemark + vbNullChar
   si50.shi50_path = UCase(lpPath) + vbNullChar
   si50.shi50_ro_password = lpPassword + vbNullChar
   si50.shi50_rw_pssword = lpPassword + vbNullChar
   si50.shi50_flags = SHI50F_PERSIST Or SHI50F_FULL
   
   lLen = Len(si50)
   
   lRtn = NetShareAdd(vbNullString, 50, si50, lLen)
   if lRtn <> 0 then debug.print "Failed to share folder"
End Function

Hope this help.
 

0
 

Author Comment

by:ianders
ID: 1456380
You 'da man.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question