Solved

Share a folder in VB

Posted on 1998-05-20
3
781 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
Comment Utility
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
Comment Utility
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
Comment Utility
You 'da man.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now