C# 利用WMI进行注册表监视

原创 2007年10月03日 11:20:00

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 objRegVaule As SWbemSink
Attribute objRegVaule.VB_VarHelpID = -1
Private WithEvents objRegTree As SWbemSink
Attribute objRegTree.VB_VarHelpID = -1
Private WithEvents objRegKey As SWbemSink
Attribute objRegKey.VB_VarHelpID = -1

Private Sub Form_Load()
    Dim objSWbemServices As SWbemServices
    'Set objRegVaule = New SWbemSink
    Set objRegTree = New SWbemSink
    Set objRegKey = New SWbemSink
    Set objSWbemServices = GetObject("winmgmts:root/default")
    'objSWbemServices.ExecNotificationQueryAsync objRegVaule, "SELECT * FROM RegistryValueChangeEvent WHERE ((Hive='HKEY_LOCAL_MACHINE' AND " & "KeyPath='SYSTEM//CurrentControlSet//Services//USBSTOR' AND ValueName='Start') Or (Hive='HKEY_LOCAL_MACHINE' AND " & "KeyPath='SYSTEM//CurrentControlSet//Control//StorageDevicePolicies' AND ValueName='WriteProtect'))"
    objSWbemServices.ExecNotificationQueryAsync objRegTree, "SELECT * FROM RegistryTreeChangeEvent WHERE Hive='HKEY_LOCAL_MACHINE' AND " & "RootPath='SYSTEM//CurrentControlSet//Services//USBSTOR'"
'    objSWbemServices.ExecNotificationQueryAsync objRegKey, "SELECT * FROM RegistryKeyChangeEvent WHERE Hive='HKEY_LOCAL_MACHINE' " & "AND KeyPath='SOFTWARE//Microsoft//Windows NT//CurrentVersion'"
End Sub


Private Sub Form_Unload(Cancel As Integer)
    'objRegVaule.Cancel
    objRegTree.Cancel
    objRegKey.Cancel
End Sub

Private Sub objRegVaule_OnObjectReady(ByVal objWbemObject As WbemScripting.ISWbemObject, ByVal objWbemAsyncContext As WbemScripting.ISWbemNamedValueSet)
    Dim swProperty As SWbemProperty, swPropertys As SWbemPropertySet
    Set swPropertys = objWbemObject.Properties_
    For Each swProperty In swPropertys
        'On Error Resume Next
        MsgBox swProperty.Name   ' & vbNewLine & swProperty.Value
    Next
End Sub


Private Sub objRegTree_OnObjectReady(ByVal objWbemObject As WbemScripting.ISWbemObject, ByVal objWbemAsyncContext As WbemScripting.ISWbemNamedValueSet)
    Dim swProperty As SWbemProperty, swPropertys As SWbemPropertySet
    Set swPropertys = objWbemObject.Properties_
'    Dim objSWbemServices As SWbemServices
'    Set objRegVaule = New SWbemSink
'    Set objSWbemServices = GetObject("winmgmts:root/default")
'    objSWbemServices.ExecNotificationQueryAsync objRegVaule, "SELECT * FROM RegistryValueChangeEvent WHERE ((Hive='HKEY_LOCAL_MACHINE' AND " & "KeyPath='SYSTEM//CurrentControlSet//Services//USBSTOR' AND ValueName='Start') Or (Hive='HKEY_LOCAL_MACHINE' AND " & "KeyPath='SYSTEM//CurrentControlSet//Control//StorageDevicePolicies' AND ValueName='WriteProtect'))"
    For Each swProperty In swPropertys
        'On Error Resume Next
        MsgBox swProperty.Name & vbNewLine & swProperty.Value
    Next
End Sub

Private Sub objRegKey_OnObjectReady(ByVal objWbemObject As WbemScripting.ISWbemObject, ByVal objWbemAsyncContext As WbemScripting.ISWbemNamedValueSet)
    Dim swProperty As SWbemProperty, swPropertys As SWbemPropertySet
    Set swPropertys = objWbemObject.Properties_
    For Each swProperty In swPropertys
        On Error Resume Next
        MsgBox swProperty.Name & vbNewLine & swProperty.Value
    Next
End Sub
 

相关文章推荐

Delphi7高级应用开发随书源码

  • 2003年04月30日 00:00
  • 676KB
  • 下载

用WMI操作注册表

REG.HTA==========================================用WMI操作注册表#lArea {  float:left;}#lArea DIV { margin:...
  • donghid
  • donghid
  • 2006年02月04日 16:25
  • 2441

vbs(with WMI) 注册表操作

1, 注册表读,写,删,注意区分主键 ,键值的区别,若为主键(key),则在strName后边加上反斜杠,键值则不用Dim WshShell, bKeySet WshShell = WScript.C...

C#:基于WMI监视USB插拔

作者:Splash 转自:http://blog.csdn.net/jhqin/article/details/6698411 参考资料: USB Port Insert / Remove ...
  • whw8007
  • whw8007
  • 2014年02月28日 08:30
  • 1106

C#:基于WMI监视USB插拔

参考资料: USB Port Insert / Remove detection using WMI USB Port Insert / Remove detection using WMI ...
  • jhqin
  • jhqin
  • 2011年08月18日 15:20
  • 7793

C#:基于WMI监视USB插拔

参考资料: USB Port Insert / Remove detection using WMI USB Port Insert / Remove detection using WMI (S...
  • dz45693
  • dz45693
  • 2011年08月18日 15:43
  • 4439

c#利用wmi远程关机

  • 2010年04月28日 17:36
  • 1KB
  • 下载

利用C#开发web应用程序时,对注册表进行操作提示没有权限的解决办法

因为公司项目需要对web程序添加一套注册机制。本人菜鸟一个,也就能想到利用...

利用C#访问注册表获取软件的安装路径

本博文使用C#访问注册表获取软件的安装路径并进行显示。
  • tiana0
  • tiana0
  • 2013年12月15日 10:51
  • 6329

怎样实现WMI查询注册表信息

  • 2013年07月17日 15:38
  • 15KB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:C# 利用WMI进行注册表监视
举报原因:
原因补充:

(最多只允许输入30个字)