Jump to content

Can This Be Written: A Script To Report When USB Keyboard/Mouse Is Unplugged


Recommended Posts

Posted

We have problems where keyboards/mice are unplugged and moved [or even go missing :mad:]

 

Does anyone have a script that can be deployed to workstations and report back to the Network Manager by E-Mail when a mouse or keyboard is unplugged/plugged in?

 

I envisage something like:

 

Station: Room19

User: 11SmithJ

Time: 10:21:23

Event: USB keyboard unplugged

 

If we had this I think I could cut down on losses/damage to/of keyboards and mice and USB ports.

 

Many thanks.

Posted

If you set it to poll usb devices, and report when certain ones aren't found yes (generic keyboard blahblah). In terms of "any mouse/any keyboard ever made etc" probably not without alot of work :(

 

Steve

  • Thanks 1
Posted

Only a rough example but:

 

Do Until i=10

strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colMice = objWMIService.ExecQuery ("Select * from Win32_PointingDevice")

if colMice.Count = 0 then
wscript.echo "oh noes, some bugger stole my mouse!"
end if


WScript.Sleep 3000


Loop

 

Should do it.

 

Basically:

 

- Infinite loop

- Check "pointer" items

- If none, send email (but I've just done echo for now)

 

Should work fine, but only quickly tested it

 

Steve

Posted

What about WMI events? e.g.

 

$query = "SELECT * FROM __InstanceCreationEvent WITHIN 5 WHERE TargetInstance ISA 'Win32_PnPEntity' AND TargetInstance.Name = 'HID Keyboard Device'"
Register-WmiEvent -Query $query -SourceIdentifier KeyboardMonitor -Action { Calc.exe }

 

In terms of "any mouse/any keyboard ever made etc" probably not without a lot of work

Wouldn't USB mice and keyboards come under either "HID-compliant mouse" or "HID Keyboard Device"? :confused:

 

Get-WmiObject Win32_PnPEntity -Filter "Name='HID Keyboard Device'"

  • Thanks 1

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



×
×
  • Create New...