How can I see the last device plugged or unplugged to my machine?
I have a loose connection somewhere... Every few minutes, I hear the device unplugged/plugged back in sound.
I can't see anything wrong and everything appears to be working.
I have tried looking in Device Manager, but, the noises seem to happen too fast or I just miss it.
I was wondering if anyone knows a way, or it would be better if you know a command that can simply tell me the last few device changes on my system?
Solution 1:
run EventGhost (http://www.eventghost.org/downloads/), when a device is attached, removed you see an event on the left side.
It includes a string with the hardware id. Now google for the ID to find the device.
Solution 2:
VBScript
Some time ago I was troubleshooting a similar issue, and for the occasion I wrote a simple script. In order to run it, save the script in a new .vbs
file, and run it through a command prompt:
cscript /nologo "X:\Path\to\script.vbs"
Here's the code:
If WScript.Arguments.Count = 0 Then
maxEvents = 10
Else
maxEvents = WScript.Arguments(0)
End If
Set wmiService = GetObject("winmgmts:\\.\root\cimv2")
Set wmiQuery = wmiService.ExecNotificationQuery _
("SELECT * FROM __InstanceDeletionEvent WITHIN 1" & _
"WHERE TargetInstance ISA 'Win32_PnPEntity'")
separator = String(40, "-")
For i = 1 To maxEvents
With wmiQuery.NextEvent.TargetInstance
WScript.Echo separator & _
vbCrLf & "Event " & i & " - " & Now & _
vbCrLf & separator & _
vbCrLf & .Name & _
vbCrLf & .DeviceID
End With
Next
How it works
An optional parameter is used to set the maximum amount of events to collect. If no amount is specified, it will record the first 10 events before quitting.
The script will then proceed to register an event provider targeting Plug and Play devices which get removed or unplugged. The polling interval is set to 1 second.
Every time there's a event notification, the script will print the results on screen, until the event amount is reached. The information includes: event number; date and time; device name and ID.
Further reading
- Monitoring Events
- Win32_PnPEntity class