+ Post New Thread
Results 1 to 7 of 7
Scripts Thread, Can This Be Written: A Script To Report When USB Keyboard/Mouse Is Unplugged in Coding and Web Development; We have problems where keyboards/mice are unplugged and moved [or even go missing ] Does anyone have a script that ...
  1. #1

    DaveP's Avatar
    Join Date
    Oct 2006
    Location
    Can't talk now: The mother-ship is calling!
    Posts
    8,795
    Thank Post
    351
    Thanked 1,274 Times in 870 Posts
    Blog Entries
    4
    Rep Power
    1126

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

    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.

  2. #2

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,689
    Thank Post
    334
    Thanked 515 Times in 483 Posts
    Rep Power
    179
    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

  3. Thanks to Steve21 from:

    DaveP (1st June 2012)

  4. #3

    DaveP's Avatar
    Join Date
    Oct 2006
    Location
    Can't talk now: The mother-ship is calling!
    Posts
    8,795
    Thank Post
    351
    Thanked 1,274 Times in 870 Posts
    Blog Entries
    4
    Rep Power
    1126
    Generic hardware is fine. Where would I find a guide on how to enable this?

  5. #4

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,689
    Thank Post
    334
    Thanked 515 Times in 483 Posts
    Rep Power
    179
    You on W7?

    Steve

  6. #5

    DaveP's Avatar
    Join Date
    Oct 2006
    Location
    Can't talk now: The mother-ship is calling!
    Posts
    8,795
    Thank Post
    351
    Thanked 1,274 Times in 870 Posts
    Blog Entries
    4
    Rep Power
    1126
    Quote Originally Posted by Steve21 View Post
    You on W7?

    Steve
    Yes. Windows 7 Pro: SP1: 64 Bit.

  7. #6

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,689
    Thank Post
    334
    Thanked 515 Times in 483 Posts
    Rep Power
    179
    Only a rough example but:

    Code:
    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

  8. #7


    Join Date
    Feb 2007
    Location
    51.405546, -0.510212
    Posts
    8,773
    Thank Post
    222
    Thanked 2,632 Times in 1,939 Posts
    Rep Power
    779
    What about WMI events? e.g.

    Code:
    $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 }
    Quote Originally Posted by Steve21 View Post
    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"?

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

  9. Thanks to Arthur from:

    mac_shinobi (1st June 2012)

SHARE:
+ Post New Thread

Similar Threads

  1. Replies: 15
    Last Post: 20th July 2011, 01:37 PM
  2. Can this be improved?
    By denon101 in forum Graphics Requests
    Replies: 4
    Last Post: 25th June 2010, 11:37 AM
  3. Can this be true?
    By laserblazer in forum Hardware
    Replies: 8
    Last Post: 2nd February 2010, 03:19 PM
  4. Replies: 16
    Last Post: 18th December 2006, 09:36 PM
  5. can this be done?
    By beeswax in forum Windows
    Replies: 6
    Last Post: 23rd June 2006, 09:30 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •