关闭

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

1047人阅读 评论(0) 收藏 举报

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
 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:324658次
    • 积分:4445
    • 等级:
    • 排名:第6966名
    • 原创:81篇
    • 转载:0篇
    • 译文:2篇
    • 评论:431条
    文章分类
    最新评论
    chenhui530新浪博客