Creating share programmatically fails with error 9

Posted by Christopher on Stack Overflow See other posts from Stack Overflow or by Christopher
Published on 2010-04-05T15:41:04Z Indexed on 2010/04/05 15:43 UTC
Read the original article Hit count: 345

Filed under:
|
|
Directory.CreateDirectory("C:\MyTestShare") 
Dim managementClass As New ManagementClass("Win32_Share") 
Dim inParams As ManagementBaseObject = managementClass.GetMethodParameters("Create") 
inParams.Item("Description") = "My Files Share" 
inParams.Item("Name") = "My Files Share" 
inParams.Item("Path") = "C:\MyTestShare" 
inParams.Item("Type") = 0 
If (DirectCast(managementClass.InvokeMethod("Create", inParams, Nothing).Properties.Item("ReturnValue").Value, UInt32) <> 0) Then 
    Throw New Exception("Unable to share directory.") 
End If

I am using the following code to set up a share, but I am always getting a return value of 9 which means invalid name. I am passing a string and have tried to use an explicit string and I still get error 9.

I am creating the share remotely rather than on local machine however. Not sure if that matter.

© Stack Overflow or respective owner

Related posts about vb

Related posts about share