Sign in to follow this  
Followers 0
kare

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

3 posts in this topic

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

--

Share this post


Link to post
Share on other sites



I am also looking for such a script. If you do find it please share it with me. Thanks a bunch!

Share this post


Link to post
Share on other sites

@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

Share this post


Link to post
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
Sign in to follow this  
Followers 0