Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Making Programmatic Shares
Message
 
 
Information générale
Forum:
Visual Basic
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00345857
Message ID:
00345915
Vues:
17
>Is anyone doing this successfully? I looked at an example from MS but it was feature poor and in C++. I would like to do it in VB. Anyone?
I've used this in the past:
Public Const STYPE_DISKTREE = 0
'Share uses
Public Const SHI_USES_UNLIMITED = -1&
'Share Access
Public Const ACCESS_READ = &H1

Declare Function NetShareAdd Lib "netapi32.dll" (ByVal _
   servername As String, ByVal Level As Long, LPBYTE As Any, _
   lpParm_Err As Long) As Long

Type SHARE_INFO_2
     ShI2_NetName As String
     ShI2_Type As Long
     ShI2_Remark As String
     ShI2_Permissions As Long
     ShI2_Max_Uses As Long
     ShI2_Current_Uses As Long
     ShI2_Path As String
     ShI2_Passwd As String
End Type

Function ShareAdd(ByVal sServerName As String, ByVal _
    sShareName As String, ByVal sPathName As String) As Boolean
    Dim pserver() As Byte, pShareName() As Byte, psharepath() As Byte
    Dim ShareInfo As SHARE_INFO_2
    Dim lsserver As String
    Dim iParamError As Long, llreturn As Long
    If sServerName = "" Then
        pserver = UCase(sServerName) + vbNullChar
    Else
        ' if it is not passed; use local machine
        lsserver = vbNullChar
    End If
    If sShareName = "" Then
        ShareAdd = False
        Exit Function
    Else
        pShareName = sShareName + vbNullChar
    End If
    If sPathName = "" Then
        ShareAdd = False
        Exit Function
    Else
        psharepath = sPathName + vbNullChar
    End If
    ShareInfo.ShI2_NetName = pShareName(0)
    ShareInfo.ShI2_Type = STYPE_DISKTREE
    ShareInfo.ShI2_Remark = vbNullChar
    ShareInfo.ShI2_Permissions = 0&
    ShareInfo.ShI2_Max_Uses = SHI_USES_UNLIMITED
    ShareInfo.ShI2_Current_Uses = 0
    ShareInfo.ShI2_Path = psharepath(0)
    ShareInfo.ShI2_Passwd = vbNullChar
    llreturn = NetShareAdd(pserver(0), 2, ShareInfo, iParamError)
    If llreturn = 0 Then
        ShareAdd = True
    Else
        ShareAdd = False
    End If
    NetAPIBufferFree (iParamError)
End Function
You have to have the access rights to create the share for the specified path.
Larry Miller
MCSD
LWMiller3@verizon.net

Accumulate learning by study, understand what you learn by questioning. -- Mingjiao
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform