Newsgroup: it.comp.lang.visual-basic
Titolo: ??? Come posso condividere cartelle da VB ???

Ciao ragazzi,
grazie in ogni caso per le risposte.
Vorrei sapere quali righe di codice
e quali API utilizzare per condividere e scondividere cartelle
da VB.
Grazie e ciao


Cerca su MSDN le funzioni NetShareAdd e NetShareDel.
hth, hal


Ho recuperato una mia risposta dell' 8 aprile che ti ricopio qui
per comodita', ma sarebbe stata recuperabile anche con google.
il copia-e-incolla e' sotto la firma :)
hth, hal
------------------------------------
Per capirci, le dichiarazioni originali, prese da msdn, sono:
Only members of the Administrators or Account Operators local group or those with Communication, Print, or Server operator group membership can successfully execute the NetShareAdd function. The Print operator can add only Printer queues. The Communication operator can add only communication-device queues.
Windows NT/2000: The parameter order is as follows.
NET_API_STATUS NetShareAdd(
  LPWSTR servername, 
  DWORD level,       
  LPBYTE buf,        
  LPDWORD parm_err   
);
Windows 95/98: You must specify the size of the information buffer, in bytes, using the cbBuffer parameter. The Windows NT/Windows 2000 parm_err parameter is not available on this platform. Therefore, the parameter list is as follows. 
extern API_FUNCTION
 NetShareAdd(
  const char FAR * pszServer,       
  short sLevel,                     
  const char FAR * pbBuffer,        
  unsigned short  cbBuffer          
);
quindi e' buona anche la dichiarazione che hai trovato, ma e' pensata per nt.
Su 
http://d.m.free.fr/VBnet.htm
 c'e' un esempio di Didier Moreau (
moreau...@free.fr
)
che ricopio qui per comodita' di documentazione, sperando che l' autore gradisca :)
(Preciso che non ho testato il codice, lasciando il compito ai miei venticinque lettori :)
-----------------------------
per Windows 9x
dim Connst STYPE_DISKTREE = 0 'Partage d'un répertoire
public Type SHARE_INFO_50 
shi50_netname(0 To 12) As Byte 'LM20_NNLEN + 1
shi50_type As Byte 'EShareType
shi50_flags As Integer
shi50_remark As Long
shi50_Path As Long
shi50_rw_password(0 To 8) As Byte 'SHPWLEN + 1
shi50_ro_password(0 To 8) As Byte 'SHPWLEN + 1
End Type
dim Const SHI50F_RDONLY = &H1
dim Const SHI50F_FULL = &H2
dim Const SHI50F_DEPENDSON = SHI50F_RDONLY+SHI50F_FULL
dim Const SHI50F_ACCESSMASK=SHI50F_RDONLY+SHI50F_FULL
dim Const SHI50F_PERSIST = &H100 'partage persistant
dim Const SHI50F_SYSTEM = &H200 'Partage caché
Declare Function NetShareAdd95 Lib "SVRAPI" Alias "NetShareAdd" _
(ByVal servername As String, _
ByVal level As Integer, _
ByVal buf As Long, _
ByVal cbBuffer As Integer) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)
Public Sub ShareResource( path As String, ShareName As String, remark As String)
Dim si50 As SHARE_INFO_50
Dim iErrParam As Integer
Dim lpszPath() As Byte
Dim lpszRemark() As Byte
Dim ShareType As Byte
flags = SHI50F_FULL Or SHI50F_PERSIST 'mode normal le partage est visible sur la machine
' flags = SHI50F_FULL Or SHI50F_PERSIST Or SHI50F_SYSTEM 'mode système partage invisible
ShareName = UCase(ShareName) 'nom de partage
path = UCase(path) 'répertoire à partager
lpszPath = StrConv(path, vbFromUnicode) & vbNullChar
lpszRemark = StrConv(remark, vbFromUnicode) & vbNullChar
With si50
StrToByte ShareName, VarPtr(.shi50_netname(0))
.shi50_type = STYPE_DISKTREE
.shi50_remark = VarPtr(lpszRemark(0))
.shi50_Path = VarPtr(lpszPath(0))
StrToByte "", VarPtr(.shi50_ro_password(0))
StrToByte "", VarPtr(.shi50_rw_password(0))
.shi50_flags = flags
End With
lreturnvalue = NetShareAdd95("", 50, ByVal VarPtr(si50), LenB(si50))
Select Case lreturnvalue
Case 0 'OK
Case 2102 'NERR_NERR_NetNotStarted
Case 2114 'NERR_ServerNotStarted
Case 2118 'NERR_ServerNotStarted
Case 2310 'NERR_NetNameNotFound
Case 124 'ERROR_INVALID_LEVEL
Case 2123 'NERR_BufTooSmall
Case 2127 'NERR_RemoteErr
Case 234 'ERROR_MORE_DATA
Case 87 'ERROR_INVALID_PARAMETER
Case Else:
End Select
End Sub
Private Sub StrToByte(strInput As String, ByVal lpByteArray As Long)
Dim lpszInput() As Byte
lpszInput = StrConv(strInput, vbFromUnicode) & vbNullChar
CopyMemory ByVal lpByteArray, lpszInput(0), UBound(lpszInput)
End Sub
------------------------------------------------------------------------------
per windows NT
STYPE_DISKTREE = 0 'Disk drive
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)
Private Type SHARE_INFO_2
netname As String
type As Long
remark As String
permissions As Long
max_uses As Long
current_uses As Long
path As String
passwd As String
End Type
Private Declare Function NetShareAddNT Lib "NETAPI32" Alias "NetShareAdd" (ByVal servername As String, ByVal level As Long, buf As SHARE_INFO_2, ByVal parm_err As Long) As Long
Global Serveur As String * 16
Global Recurso As String
Public Sub shareNT(disque As String, partage As String, valeur As Integer, remarque As String)
On Error Resume Next
Dim n As Long
Dim bufNT As SHARE_INFO_2
Dim error As Long
n = 0
bufNT.netname = StrConv(partage & vbNullChar, vbUnicode)
bufNT.type = 0 ' STYPE_DISKTREE
bufNT.remark = StrConv(remarque & vbNullChar, vbUnicode)
bufNT.permissions = 0
bufNT.max_uses = -1
bufNT.current_uses = 0
bufNT.path = StrConv(disque & vbNullChar, vbUnicode)
bufNT.passwd = StrConv("" & vbNullChar, vbUnicode)
n = NetShareAddNT(StrConv("", vbUnicode), 2, bufNT, error)
Select Case lreturnvalue
Case 0 'OK
Case 2102 'NERR_NERR_NetNotStarted Networking has not been started on this computer.
Case 2114 'NERR_ServerNotStarted The server has not been started on this computer
Case 2118 'NERR_ServerNotStarted The name has already been shared
Case 2310 'NERR_NetNameNotFound The computer was not found
Case 124 'ERROR_INVALID_LEVEL Invalid level for server_info structure
Case 2123 'NERR_BufTooSmall The buffer size specified for the server_info structure was too small
Case 2127 'NERR_RemoteErr There has been an error on the remote computer
Case 234 'ERROR_MORE_DATA More data is available
Case 87 'ERROR_INVALID_PARAMETER An invalid parameter has been passed to NetShareAdd
Case Else:
End Select
End Sub
Function version_windows() As Integer
Dim n As Long
Dim error As Long
Dim v As OSVERSIONINFO, retval As Long
Dim WindowsVersion As String, BuildVersion As String
Dim PlatformName As String
v.dwOSVersionInfoSize = Len(v)
retval = GetVersionEx(v)
WindowsVersion = v.dwMajorVersion & "." & v.dwMinorVersion
BuildVersion = v.dwBuildNumber And &HFFFF&
Select Case v.dwPlatformId
Case VER_PLATFORM_WIN32_NT:
If WindowsVersion <> "5.0" Then
version_windows = 1
Else
version_windows = 0
End If
Case Else: version_windows = 0
End Select
End Function
-------------------------------------------------------------------
Scusate la schifezza di indentazione, ma mi sono limitato a fare copia/incolla.
ciao, hal
 

...


 ciao, ora proverò
[...]
Magari la prossima volta per dire grazie (cosa peraltro sacrosanta), non
quotare 8kb di post, fai uno snip.
Ciao
Alfonso