打印本文 打印本文 关闭窗口 关闭窗口
VB.NET下通过WMI共享文件夹
作者:武汉SEO闵涛  文章来源:敏韬网  点击数3526  更新时间:2009/4/23 19:00:36  文章录入:mintao  责任编辑:mintao
;   '''''''''''' </history>
        '''''''''''' -----------------------------------------------------------------------------
        Public Sub Delete()

            Dim res As Integer

            res = Convert.ToInt32(_share.InvokeMethod("Delete", Nothing), CultureInfo.InvariantCulture)

            If res <> 0 Then ThrowException(res)

        End Sub

        Public Sub Dispose() Implements System.IDisposable.Dispose

            '''' Dispose the WMI object
            _share.Dispose()

            GC.SuppressFinalize(Me)

        End Sub

        '''''''''''' -----------------------------------------------------------------------------
        '''''''''''' <summary>
        '''''''''''' Sets the share info.
        '''''''''''' </summary>
        '''''''''''' <remarks>The security descriptor is not supported by this class.</remarks>
        '''''''''''' <history>
        '''''''''''' [Eduardo Morcillo] 11/08/2004 Created
        '''''''''''' </history>
        '''''''''''' -----------------------------------------------------------------------------
        Private Sub SetShareInfo( _
                    ByVal maximumAllowed As Integer, _
                    ByVal description As String, _
                    ByVal descriptor As ManagementBaseObject)

            Dim res As Integer

            '''' Set the share info
            res = Convert.ToInt32(_share.InvokeMethod("SetShareInfo", New Object() {maximumAllowed, description, descriptor}), CultureInfo.InvariantCulture)

            If res <> 0 Then ThrowException(res)

        End Sub

        '''''''''''' -----------------------------------------------------------------------------
        '''''''''''' <summary>
        '''''''''''' Throws an exception for the specified WMI error number.
        '''''''''''' </summary>
        '''''''''''' <history>
        '''''''''''' [Eduardo Morcillo] 11/08/2004 Created
        '''''''''''' </history>
        '''''''''''' -----------------------------------------------------------------------------
        Private Shared Sub ThrowException(ByVal res As Integer)

            Select Case res

                Case 2  '''' Access denied
                    Throw New Win32Exception(65)
                Case 9  '''' Invalid name
                    Throw New Win32Exception(1215)
                Case 10 '''' Invalid level
                    Throw New Win32Exception(124)
                Case 21 '''' Invalid parameter
                    Throw New Win32Exception(87)
                Case 22 '''' Duplicate Share
                    Throw New Win32Exception(2118)
                Case 23 '''' Redirected Path
                    Throw New Win32Exception(2117)
                Case 24 '''' Unknown device Or directory
                    Throw New Win32Exception(2116)
                Case 25 '''' Net name not found
                    Throw New Win32Exception(67)
                Case Else
                    Throw New Exception("Unknown error: " & res)

            End Select

        End Sub

    End Class

    Public Enum ShareType As Integer
        DiskDrive = 0
        PrintQueue = 1
        Device = 2
        Ipc = 3
        DiskDriveAdmin = &H80000000
        PrintQueueAdmin = &H80000001
        DeviceAdmin = &H80000002
        IpcAdmin = &H80000003
    End Enum

    <Flags()> Public Enum AccessMasks As Integer
        ListDirectory = &H1
        AddFile = &H2
        AddSubdirectory = &H4
        ReadExtendedAttributes = &H8
        WriteExtendedAttributes = &H10
        Traverse = &H20
        DeleteChild = &H40
        ReadAttributes = &H80
        WriteAttributes = &H100
        Delete = &H10000
        ReadControl = &H20000
        WriteDac = &H40000
        WriteOwner = &H80000
        Synchronize = &H100000

        Read = ListDirectory Or ReadExtendedAttributes Or ReadAttributes Or ReadControl Or Synchronize
        ReadAndExecute = Read Or Traverse
        Write = AddFile Or AddSubdirectory Or WriteExtendedAttributes Or WriteAttributes Or Synchronize
        Modify = Read Or Write Or Delete Or Traverse
        FullControl = DeleteChild Or WriteDac Or WriteOwner Or Modify

    End Enum

End Namespace


http://www.applevb.com

上一页  [1] [2] [3] [4] 

打印本文 打印本文 关闭窗口 关闭窗口