Difference between revisions of "Sharing in VbNET"
(Sharing Files and Folders in VB.NET) |
(Sharing Files and Folders in VB.NET) |
||
| Line 9: | Line 9: | ||
---- | ---- | ||
| − | <nowiki>Public Sub QshareFolder(ByVal FolderPath As String, ByVal ShareName As String, ByVal Description As String) | + | First of all, u need add the System.Management reference. This must be definied as public in the Generals Declarations of the app. |
| + | |||
| + | |||
| + | 'After, the public function called QshareFolder. 'This example is for folders, but u can change the values for files. 'Read the ManagementBaseObject MSDN. Also u can add more inParameters values. | ||
| + | |||
| + | ---- | ||
| + | |||
| + | <nowiki> | ||
| + | |||
| + | 'Importing the reference | ||
| + | Imports System.Management | ||
| + | |||
| + | |||
| + | Public Sub QshareFolder(ByVal FolderPath As String, ByVal ShareName As String, ByVal Description As String) | ||
Try | Try | ||
'Create a ManagementClass object | 'Create a ManagementClass object | ||
Latest revision as of 19:18, 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
This link can be usefull too:
http://msdn2.microsoft.com/en-us/library/system.management.managementobject.invokemethod(VS.71).aspx
First of all, u need add the System.Management reference. This must be definied as public in the Generals Declarations of the app.
'After, the public function called QshareFolder. 'This example is for folders, but u can change the values for files. 'Read the ManagementBaseObject MSDN. Also u can add more inParameters values.
'Importing the reference
Imports System.Management
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