Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact


Share folder or drive


Share folder or drive

Author
Message
goodluck
goodluck
Forum God
Forum God (1K reputation)Forum God (1K reputation)Forum God (1K reputation)Forum God (1K reputation)Forum God (1K reputation)Forum God (1K reputation)Forum God (1K reputation)Forum God (1K reputation)Forum God (1K reputation)

Group: Forum Members
Posts: 8, Visits: 1

Anyone can  u tell me i don know the code for sharing folder or drive in VB.just give me small sample.

Thanks for helping.



@@@
Mark
Mark
Forum God
Forum God (139K reputation)

Group: Moderators
Posts: 1.1K, Visits: 11K

I'm not sure if there is a easier way or not. This will work for Win2k and I'm pretty sure WinXP. Not sure about earlier versions of windows.

Place this in a module -
Option Explicit
Private Const STYPE_DISKTREE As Long = 0 'disk drive
Private Const STYPE_PRINTQ As Long = 1 'printer
Private Const STYPE_DEVICE As Long = 2
Private Const STYPE_IPC As Long = 3

Private Type SHARE_INFO_2
    shi2_netname As String 'LPWSTR
    shi2_type As Long 'DWORD
    shi2_remark As String 'LPWSTR
    shi2_permissions As Long 'DWORD
    shi2_max_uses As Long 'DWORD
    shi2_current_uses As Long 'DWORD
    shi2_path As String 'LPWSTR
    shi2_passwd As String 'LPWSTR
End Type

Private Declare Function NetShareAdd Lib "netapi32.dll" ( _
                        lpwstrServerName As Byte, _
                        ByVal dwordLevel As Long, _
                        ByVal lpbyteBuf As Long, _
                        lpdwordParmErr As Long) As Long
   


Public Function ShareIt(ByVal CompterName As String, _
                        ByVal SharePath As String, _
                        Optional ShareName As String = " ", _
                        Optional ByVal ShareRemarks As String = " ") As Long
' This function returns 0 if successful and
' a none zero number if the function fails.

Dim si2 As SHARE_INFO_2
Dim parmerr As Long
Dim compname() As Byte
   
    parmerr = 0
    compname() = CompterName & vbNullChar
   
    si2.shi2_netname = ShareName 'the name of the share
    si2.shi2_type = STYPE_DISKTREE 'the share is on the disk
    si2.shi2_remark = ShareRemarks & vbNullChar 'the comment
    si2.shi2_permissions = 0 'this should be ignored
    si2.shi2_max_uses = -1 'unlimited connections
    si2.shi2_current_uses = 0 'I don't think this is applicable
    si2.shi2_path = SharePath  'the path to the share
    si2.shi2_passwd = vbNullString ' the password 'this should be ignored
   
    ShareIt = NetShareAdd(compname(0), 2, VarPtr(si2), parmerr)
   
End Function

 

And to use it, call it from your form like this -
Private Sub Command1_Click()
    If ShareIt("CC687927-b", "c:\temp") = 0 Then
        MsgBox "The share was created"
    Else
        MsgBox
"The share could not be created with the information you supplied"
    End If
   
'    'to share a drive
'    If ShareIt("CC687927-b", "c:\") = 0 Then
End Sub


Dark Star
Dark Star
Forum God
Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)

Group: Forum Members
Posts: 76, Visits: 1
Yep mark, there is an easier way to do it:
Just use a batch command:
Netshare

So:
Shell "net share C=C:"

To share the whole C drive, hope it works.
Intersting method you had there Mark, never new how that one was done, thanks

Booooze
Booooze
Forum God
Forum God (149K reputation)Forum God (149K reputation)Forum God (149K reputation)Forum God (149K reputation)Forum God (149K reputation)Forum God (149K reputation)Forum God (149K reputation)Forum God (149K reputation)Forum God (149K reputation)

Group: Forum Members
Posts: 827, Visits: 132
yours is nice to Dark Star, never knew you could do that

API Guide|Inno Setup Wizard|Winsockvb|StudioTraffic|Firefox
Digitalmetal
Digitalmetal
Supreme Being
Supreme Being (270 reputation)Supreme Being (270 reputation)Supreme Being (270 reputation)Supreme Being (270 reputation)Supreme Being (270 reputation)Supreme Being (270 reputation)Supreme Being (270 reputation)Supreme Being (270 reputation)Supreme Being (270 reputation)

Group: Forum Members
Posts: 2, Visits: 14
Hello,

I came across you message bord while looking for an answer to a problem with 'Net Share'

in windows XP useing net share

exp. 'net share c=c'

will set the folder or drive to share and is visiable by other computer on the network, but are not access able.

you receive an error message

Metal

GO


Similar Topics


Reading This Topic


Login
Existing Account
Email Address:


Password:


Social Logins

Select a Forum....

















A1VBCode Forums


Search