Jump to content

USB drive Monitor Example


ptrex
 Share

Recommended Posts

please can you tel me, how i can get the removal drive latter from this code like H: M: L:. i want to know which drive is latter is created by the removal detection...thank you...please

$strComputer = "."
 $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")

 $colEvents = $objWMIService.ExecNotificationQuery _
    ("Select * From __InstanceOperationEvent Within 5 Where " _
        & "TargetInstance isa 'Win32_LogicalDisk'")

While 1
     $objEvent = $colEvents.NextEvent
    If $objEvent.TargetInstance.DriveType = 2 Then 
        Select 
            Case $objEvent.Path_.Class()="__InstanceCreationEvent"
                Consolewrite("Drive " & $objEvent.TargetInstance.DeviceId & "has been added." & @CR)
            Case $objEvent.Path_.Class()="__InstanceDeletionEvent"
                Consolewrite("Drive " & $objEvent.TargetInstance.DeviceId & "has been removed."& @CR)
        EndSelect
    EndIf
WEnd
quick edit, not testing, try it :)

$strComputer = "."
 $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")

 $colEvents = $objWMIService.ExecNotificationQuery _
    ("Select * From __InstanceOperationEvent Within 5 Where " _
        & "TargetInstance isa 'Win32_LogicalDisk'")

While 1
     $objEvent = $colEvents.NextEvent
    If $objEvent.TargetInstance.DriveType = 2 Then 
        Select 
            Case $objEvent.Path_.Class()="__InstanceCreationEvent"
                Consolewrite("Drive " & $objEvent.TargetInstance.Name & "has been added." & @CR)
            Case $objEvent.Path_.Class()="__InstanceDeletionEvent"
                Consolewrite("Drive " & $objEvent.TargetInstance.Name & "has been removed."& @CR)
        EndSelect
    EndIf
WEnd

-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...