Jump to content

How to detect a Device Being plugged-in or unplugged?


kare
 Share

Recommended Posts

Hello Autoit-Freaks

I'm trying to make a program what can let me know when a PCI, USB, or other device is added

or removed from a system.

please without devcon.exe solution. maybe with a dll-call.

greetings

kare

--

Link to comment
Share on other sites

  • 4 weeks later...

@all

You can play around with this.

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

 $colEvents = $objWMIService.ExecNotificationQuery _
    ("Select * From __InstanceOperationEvent Within 10 Where " _
        & "TargetInstance isa 'Win32_LogicalDisk'") ;and " _ 
          ; & "TargetInstance.DriveType = 2" )


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

; Types
; 0 Unknown 
; 1 No Root Directory 
; 2 Removable Disk 
; 3 Local Disk 
; 4 Network Drive 
; 5 Compact Disc 
; 6 RAM Disk

regards,

ptrex

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...