6Foot2 Posted June 1, 2012 Posted June 1, 2012 We have problems where keyboards/mice are unplugged and moved [or even go missing ] 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.
Steve21 Posted June 1, 2012 Posted June 1, 2012 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 1
6Foot2 Posted June 1, 2012 Author Posted June 1, 2012 Generic hardware is fine. Where would I find a guide on how to enable this?
6Foot2 Posted June 1, 2012 Author Posted June 1, 2012 You on W7? Steve Yes. Windows 7 Pro: SP1: 64 Bit.
Steve21 Posted June 1, 2012 Posted June 1, 2012 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
Arthur Posted June 1, 2012 Posted June 1, 2012 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"? Get-WmiObject Win32_PnPEntity -Filter "Name='HID Keyboard Device'" 1
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now