Solved

Share a folder in VB

Posted on 1998-05-20
3
786 Views
Last Modified: 2008-02-01
How can I programmatically share a folder, including rights and password, from VB?
0
Comment
Question by:ianders
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…

752 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