上一篇 | 下一篇

VB.NET下通过WMI共享文件夹

发布: 2008-6-26 22:13 | 作者: admin | 来源: | 查看: 9次

Option Explicit On

Option Strict On

Imports System

Imports System.Collections

Imports System.ComponentModel

Imports System.Globalization

Imports System.Management

Namespace Edanmo.IO

Public NotInheritable Class NetShare

Implements IDisposable

Private _share As ManagementObject

Private Sub New(ByVal share As ManagementObject)

_share = share

End Sub

''' -----------------------------------------------------------------------------

'''

''' Gets the share access rights for the current user or group.

'''

'''

''' [Eduardo Morcillo] 11/08/2004 Created

'''

''' -----------------------------------------------------------------------------

Public ReadOnly Property AccessMask() As AccessMasks

Get

Return CType(Convert.ToInt32(_share.InvokeMethod("GetAccessMask", Nothing), CultureInfo.InvariantCulture), AccessMasks)

End Get

End Property

''' -----------------------------------------------------------------------------

'''

''' Gets or sets the maximum number of user connections.

'''

'''

''' [Eduardo Morcillo] 11/08/2004 Created

'''

''' -----------------------------------------------------------------------------

Public Property AllowMaximum() As Integer

Get

Return Convert.ToInt32(_share.GetPropertyValue("AllowMaximum"), CultureInfo.InvariantCulture)

End Get

Set(ByVal value As Integer)

Me.SetShareInfo(value, Me.Description, Nothing)

End Set

End Property

''' -----------------------------------------------------------------------------

'''

''' Gets the share description.

'''

'''

''' [Eduardo Morcillo] 11/08/2004 Created

'''

''' -----------------------------------------------------------------------------

Public Property Description() As String

Get

Return _share.GetPropertyValue("Description").ToString

End Get

Set(ByVal value As String)

Me.SetShareInfo(Me.MaximumAllowed, value, Nothing)

End Set

End Property

''' -----------------------------------------------------------------------------

'''

''' Gets

'''

'''

''' [Eduardo Morcillo] 11/08/2004 Created

'''

''' -----------------------------------------------------------------------------

Public Property MaximumAllowed() As Integer

Get

Return Convert.ToInt32(_share.GetPropertyValue("MaximumAllowed"), CultureInfo.InvariantCulture)

End Get

Set(ByVal value As Integer)

Me.SetShareInfo(value, Me.Description, Nothing)

End Set

End Property

''' -----------------------------------------------------------------------------

'''

''' Gets the share name.

'''

'''

''' [Eduardo Morcillo] 11/08/2004 Created

'''

''' -----------------------------------------------------------------------------

Public ReadOnly Property Name() As String

Get

Return _share.GetPropertyValue("Name").ToString

End Get

End Property

''' -----------------------------------------------------------------------------

'''

''' Gets the local path of the share.

'''

'''

''' [Eduardo Morcillo] 11/08/2004 Created

'''

''' -----------------------------------------------------------------------------

Public ReadOnly Property Path() As String

Get

Return _share.GetPropertyValue("Path").ToString

End Get

End Property

''' -----------------------------------------------------------------------------

'''

''' Gets the share status.

'''

'''

''' [Eduardo Morcillo] 11/08/2004 Created

'''

''' -----------------------------------------------------------------------------

Public ReadOnly Property Status() As String

Get

Return _share.GetPropertyValue("Status").ToString

End Get

End Property

''' -----------------------------------------------------------------------------

'''

''' Gets the share type.

'''

'''

''' [Eduardo Morcillo] 11/08/2004 Created

'''

''' -----------------------------------------------------------------------------

Public ReadOnly Property Type() As ShareType

Get

Dim typeValue64 As Long = Convert.ToInt64(_share.GetPropertyValue("Type"), CultureInfo.InvariantCulture)

Dim typeValue32 As Integer

If (typeValue64 And &H80000000) > 0 Then

typeValue32 = &H80000000 Or Convert.ToInt32(typeValue64 And &H7FFFFFFF, CultureInfo.InvariantCulture)

Else

typeValue32 = Convert.ToInt32(typeValue64, CultureInfo.InvariantCulture)

End If

Return CType(typeValue32, ShareType)

End Get

End Property

''' -----------------------------------------------------------------------------

字号: | 推荐给好友

31/3123>

评分:0

我来说两句

网络推荐