我可以使用以下代码在本地网络上共享文件夹,但是我不知道如何像使用“ net share”那样设置权限/ maxuser。
有人知道怎么做吗?
Public Function CreateUNCPath(ByVal uPath As String, ByVal uShareName As String, ByVal uDescription As String) As Boolean
Debug.Assert(modIO.DirectoryExists(uPath))
uPath = Replace(uPath, "\", "/")
Try
Dim managementClass As New ManagementClass("Win32_Share")
Dim inParams As ManagementBaseObject = managementClass.GetMethodParameters("Create")
inParams("Description") = uDescription ' "My Description"
inParams("Name") = uShareName ' "Share Name"
inParams("Path") = uPath ' "C:/My Folder"
inParams("Type") = &H0
Dim outParams As ManagementBaseObject = managementClass.InvokeMethod("Create", inParams, Nothing)
Dim iRet As Integer = Convert.ToUInt32(outParams.Properties("ReturnValue").Value)
If iRet <> 0 Then
'2 = access denied
'22=duplicated
MessageBox.Show("Unable to share directory. Error: " & iRet)
Return False
Else
MessageBox.Show("Shared folder successfully!")
Return True
End If
Catch ex As Exception
MessageBox.Show("Error in function pCreateUNCPath." & NewLines(2) & ex.Message)
Return False
End Try
End Function