VB 利用WMI进行外界设备插入分配盘符监视

原创 2007年10月03日 11:30: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 CreateDriveEvent As SWbemSink
Attribute CreateDriveEvent.VB_VarHelpID = -1
Private WithEvents DeleteDriveEvent As SWbemSink
Attribute DeleteDriveEvent.VB_VarHelpID = -1
Private WithEvents ModificationDriveEvent As SWbemSink
Attribute ModificationDriveEvent.VB_VarHelpID = -1
Private objSWbemServices As SWbemServices

Private Sub Form_Load()
    StartMonitorCreateDriveEvent
    StartMonitorDeleteDriveEvent
'    StartMonitorModificationDriveEvent
End Sub


Private Sub Form_Unload(Cancel As Integer)
    CreateDriveEvent.Cancel
    DeleteDriveEvent.Cancel
'    ModificationDriveEvent.Cancel
End Sub

'驱动器创建事件
Private Sub CreateDriveEvent_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 DeleteDriveEvent_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 ModificationDriveEvent_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 StartMonitorCreateDriveEvent()
    Set CreateDriveEvent = New SWbemSink
    Set objSWbemServices = GetObject("winmgmts://./root/cimv2")
    objSWbemServices.ExecNotificationQueryAsync CreateDriveEvent, "SELECT * FROM __InstanceCreationEvent WITHIN 1 WHERE TargetInstance ISA 'Win32_LogicalDisk'"
End Sub

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

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

自动得到USB存储设备盘符

  • 2009年03月31日 11:23
  • 1.84MB
  • 下载

使用udev管理 Linux 设备文件 防止盘符改变---multipath用udev更改权限

使用udev管理 Linux 设备文件 防止盘符改变 网址: http://www.eygle.com/digest/2012/03/udev_linux_bind.html 原文链接: h...

通过U盘的盘符找到USB设备

1.判断磁盘的类型     if (GetDriveType(szRootPathName) != DRIVE_REMOVABLE)     {         m_csErrorMsg.For...

Android系统之路(初识MTK) ------ 更改设备盘符名称/型号/名称/品牌/Version/Devices/Product......

Android系统之路(初识MTK) ------ 更改设备盘符名称/型号/名称/品牌/Version/Devices/Product.........
  • jspping
  • jspping
  • 2016年01月06日 11:36
  • 3590

TrueCrypt代码 之 通过磁盘设备名获取到对应盘符

TrueCrypt 提供了一种通过驱动获取磁盘设备路径对应盘符的方法,需要依赖TrueCrypt驱动提供的CC_IOCTL_GET_RESOLVED_SYMLINK消息来获取,代码如下 BOOL R...
  • cncrypt
  • cncrypt
  • 2016年07月14日 14:52
  • 513

VB 获取硬盘的所有盘符

  • 2011年05月15日 12:02
  • 4KB
  • 下载

Android系统移植与调试之------->如何修改Android设备存储盘符名称与Android设备的型号

一、修改Android设备存储盘符名称 (注:TBDG1073为我的项目名称) 1、修改device/other/TBDG1073/system.prop 文件 ...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:VB 利用WMI进行外界设备插入分配盘符监视
举报原因:
原因补充:

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