Программно расшарить папку в сети И установить права - PullRequest
0 голосов
/ 25 сентября 2018

Я могу открыть общий доступ к папке в локальной сети с помощью приведенного ниже кода, но я понятия не имею, как я могу установить разрешения / maxuser, как я могу с помощью «net share».

Кто-нибудь знает, каксделать это?

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
...