How to share the folder using vb.net code  
Author Message
Irshad_ip





PostPosted: .NET Framework Networking and Communication, How to share the folder using vb.net code Top

 

Hi ,

      I have to share a folder using vb.net, i do that using net share command in shell but want to do that using vb.net code. so plz anyone help me.

IRSHAD SHAIKH

 

 

 



.NET Development21  
 
 
ahmedilyas





PostPosted: .NET Framework Networking and Communication, How to share the folder using vb.net code Top

you would require some WMI to do this.

it can be done this way. You need to add a reference to System.Management and import the System.Management and System.Management.Instrumentation namespaces


Try


Dim managementClass As New ManagementClass("Win32_Share")
Dim inParams As ManagementBaseObject = managementClass.GetMethodParameters("Create")

inParams(
"Description") = "My Description"

inParams("Name") = "Share Name"

inParams("Path") = "C:\My Folder"

inParams("Type") = &H0
Dim outParams As ManagementBaseObject = managementClass.InvokeMethod("Create", inParams, Nothing)
If Convert.ToUInt32(outParams.Properties("ReturnValue").Value) <> 0 Then

MessageBox.Show("Unable to share directory.")
else
MessageBox.Show("Shared folder successfully!")
End If

Catch ex As Exception
MessageBox.Show(ex.Message)
End Try



 
 
jjchern





PostPosted: .NET Framework Networking and Communication, How to share the folder using vb.net code Top

The above code is ok. But I can't see the sharing-icon ( a hand) showed after runing this program. Why

And the shared folder is read-and-write available, how do I share a folder with read-only permission

And how do I stop sharing

Thanks a lot.


 
 
Jeremy6996





PostPosted: .NET Framework Networking and Communication, How to share the folder using vb.net code Top

I don't know how to do this in VB.net code, but you can change the folder properties in the hosts computer so only the Hosts User has write to read\write to the folder.