VB 利用WMI进行共享目录的监视

VERSION 5.00
Begin VB.Form frmMain
   Caption         =   "Form1"
   ClientHeight    =   3090
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   ScaleHeight     =   3090
   ScaleWidth      =   4680
   StartUpPosition =   3  '窗口缺省
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private WithEvents CreateProcessEvent As SWbemSink
Attribute CreateProcessEvent.VB_VarHelpID = -1
Private WithEvents DeleteProcessEvent As SWbemSink
Attribute DeleteProcessEvent.VB_VarHelpID = -1
Private WithEvents ModificationProcessEvent As SWbemSink
Attribute ModificationProcessEvent.VB_VarHelpID = -1
Private objSWbemServices As SWbemServices

Private Sub Form_Load()
    StartMonitorCreateProcessEvent
    StartMonitorDeleteProcessEvent
    StartMonitorModificationProcessEvent
End Sub


Private Sub Form_Unload(Cancel As Integer)
    CreateProcessEvent.Cancel
    DeleteProcessEvent.Cancel
    ModificationProcessEvent.Cancel
End Sub

'共享创建事件
Private Sub CreateProcessEvent_OnObjectReady(ByVal objWbemObject As WbemScripting.ISWbemObject, ByVal objWbemAsyncContext As WbemScripting.ISWbemNamedValueSet)

    MsgBox objWbemObject.Properties_.Item("TargetInstance").Value.Properties_.Item("Name").Value

End Sub
'dim ss as WbemScripting.
 

'共享删除事件
Private Sub DeleteProcessEvent_OnObjectReady(ByVal objWbemObject As WbemScripting.ISWbemObject, ByVal objWbemAsyncContext As WbemScripting.ISWbemNamedValueSet)
    MsgBox objWbemObject.Properties_.Item("TargetInstance").Value.Properties_.Item("path").Value
End Sub

'共享属性变更事件
Private Sub ModificationProcessEvent_OnObjectReady(ByVal objWbemObject As WbemScripting.ISWbemObject, ByVal objWbemAsyncContext As WbemScripting.ISWbemNamedValueSet)
    MsgBox objWbemObject.Properties_.Item("TargetInstance").Value.Properties_.Item("Name").Value
End Sub


Private Sub StartMonitorCreateProcessEvent()
    Set CreateProcessEvent = New SWbemSink
    Set objSWbemServices = GetObject("winmgmts://./root/cimv2")
    objSWbemServices.ExecNotificationQueryAsync CreateProcessEvent, "SELECT * FROM __InstanceCreationEvent WITHIN 1 WHERE TargetInstance ISA 'Win32_Share'"
End Sub

Private Sub StartMonitorDeleteProcessEvent()
    Set DeleteProcessEvent = New SWbemSink
    Set objSWbemServices = GetObject("winmgmts://./root/cimv2")
    objSWbemServices.ExecNotificationQueryAsync DeleteProcessEvent, "SELECT * FROM __InstanceDeletionEvent WITHIN 1 WHERE TargetInstance ISA 'Win32_Share'"
End Sub

Private Sub StartMonitorModificationProcessEvent()
    Set ModificationProcessEvent = New SWbemSink
    Set objSWbemServices = GetObject("winmgmts://./root/cimv2")
    objSWbemServices.ExecNotificationQueryAsync ModificationProcessEvent, "SELECT * FROM __InstanceModificationEvent WITHIN 1 WHERE TargetInstance ISA 'Win32_Share'"
End Sub
 

阅读更多
文章标签: vb integer path
想对作者说点什么? 我来说一句

VB监控文件目录修改

2015年01月16日 11KB 下载

没有更多推荐了,返回首页

不良信息举报

VB 利用WMI进行共享目录的监视

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭