Results 1 to 2 of 2

Thread: Sharing a folder to network thru program

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2001
    Posts
    6

    Sharing a folder to network thru program

    How can i share folder in a machine programatically. ( I mean right click on a folder and sharing steps should get done thru program)

  2. #2
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    VB Code:
    1. 'THIS CODE IS FOR NT/2000
    2. '5-3-2001 by JoshT
    3.  
    4. Option Explicit
    5. Option Base 0
    6.  
    7. Private Const STYPE_DISKTREE As Long = 0 'disk drive
    8. Private Const STYPE_PRINTQ As Long = 1 'printer
    9. Private Const STYPE_DEVICE As Long = 2
    10. Private Const STYPE_IPC As Long = 3
    11.  
    12. Private Type SHARE_INFO_2
    13.     shi2_netname As String 'LPWSTR
    14.     shi2_type As Long 'DWORD
    15.     shi2_remark As String 'LPWSTR
    16.     shi2_permissions As Long 'DWORD
    17.     shi2_max_uses As Long 'DWORD
    18.     shi2_current_uses As Long 'DWORD
    19.     shi2_path As String 'LPWSTR
    20.     shi2_passwd As String 'LPWSTR
    21. End Type
    22.  
    23. 'NetShareAdd returns 0 if no error
    24. '
    25. 'lpwstrServerName As Any, --the computer to create the share on,
    26. '                           NULL for local computer,
    27. '                           otherwise must begin with "\\"
    28. 'ByVal dwordLevel As Long, -- specifies the type struct that contains the data
    29. '       2 for SHARE_INFO_2 Struct
    30. '       502 for SHARE_INFO_502 Struct
    31. 'ByVal lpbyteBuf As Any, -- pointer to the struct who type was specified above
    32. 'lpdwordParmErr As Long, -- if an error in the struct, the number of the struct's parameter
    33. '                            that caused the error (0 is no error)
    34.  
    35. Private Declare Function NetShareAdd Lib "netapi32.dll" _
    36.     (lpwstrServerName As Byte, _
    37.     ByVal dwordLevel As Long, _
    38.     ByVal lpbyteBuf As Long, _
    39.     lpdwordParmErr As Long) As Long
    40.    
    41.  
    42.  
    43. Private Sub TestIt()
    44.     Dim si2 As SHARE_INFO_2
    45.     Dim retval As Long
    46.     Dim parmerr As Long
    47.     Dim compname() As Byte
    48.    
    49.     parmerr = 0
    50.     'compname = vbNullString
    51.     compname() = "\\COMPNAME" & vbNullChar
    52.    
    53.     si2.shi2_netname = "Test2C" & vbNullChar 'the name of the share
    54.     si2.shi2_type = STYPE_DISKTREE 'the share is on the disk
    55.     si2.shi2_remark = "Testing Out NetShareAdd VB API" & vbNullChar 'the comment
    56.     si2.shi2_permissions = 0 'this should be ignored
    57.     si2.shi2_max_uses = -1 'unlimited connections
    58.     si2.shi2_current_uses = 0 'I don't think this is applicable
    59.     si2.shi2_path = "C:\TEMP" & vbNullChar 'the path to the share
    60.     si2.shi2_passwd = vbNullString 'NULL, the password 'this should be ignored
    61.     retval = NetShareAdd(compname(0), 2, VarPtr(si2), parmerr)
    62.    
    63. End Sub
    64.  
    65. Private Sub Form_Load()
    66.     TestIt
    67. End Sub
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width