Difference between revisions of "Sharing in VbNET"
From HashVB
(Sharing Files and Folders in VB.NET) |
(No difference)
|
Revision as of 18:50, 24 July 2007
This code is for sharing folders or files in vb.net using the System.Management references.
I transcode it from C in:
http://www.codeproject.com/useritems/Share-Folder-c_.asp?df=100&forumid=413715&exp=0&select=2024187
Public Sub QshareFolder(ByVal FolderPath As String, ByVal ShareName As String, ByVal Description As String)
Try
'Create a ManagementClass object
Dim ManagementClass As New ManagementClass("Win32_Share")
' Create ManagementBaseObjects for in and out parameters
Dim inParams As ManagementBaseObject = ManagementClass.GetMethodParameters("Create")
Dim outParams As ManagementBaseObject
' Set the input parameters
inParams("Description") = Description
inParams("Name") = ShareName
inParams("Path") = FolderPath
inParams("Type") = 0 'Disk Drive
outParams = ManagementClass.InvokeMethod("Create", inParams, Nothing)
If outParams.Properties("ReturnValue").Value <> 0 Then
'error if u cant do it
End If
Catch ex As Exception
'error if u cant do it
End Try
End Sub
This work perfect for me, in VB.NET 2005 NF2 SP2 (XP)
Its my first contribution, so sorry for my poor english :)
Nocturno - Nocturno27
msn@sistemasmd.com.ar