1

I know a little bit about programming. I wanted to know if there was a way to get a message box pop up every time someone plugs in a usb drive saying something like "is this an approved device?" . I was wondering if there was a way to insert this in a registry entry or something? Or maybe you have an idea on how to do this.

Lars Truijens
  • 42,837
  • 6
  • 126
  • 143
Mike Q
  • 6,716
  • 5
  • 55
  • 62
  • What do you mean with 'insert in registry or something'? With that purpose? And please ask each question in a separate post. – Lars Truijens May 04 '13 at 12:57
  • One hope was to avoid writing a memory resident application. That perhaps the registry could handle this for me. – Mike Q May 04 '13 at 14:58
  • Hi, All I neeed is a pop-up message to happen when someone plugs in a USB stick. That is the entire application, nothing more. I was hoping that maybe there were settings in Windows which could make this easier. – Mike Q May 04 '13 at 15:00
  • Although you could use PowerShell to make a process running in the background, it is probably not the best tool for the job. Of course you are welcome to try. If you have any more questions when writing your script, you know where to ask. – Lars Truijens May 04 '13 at 19:28
  • I know if no setting in Windows that could do what you want other then Windows already showing a dialog when inserting an USB stick, but I guess serverfault.com or superuser.com is probably a better place for such questions. – Lars Truijens May 04 '13 at 19:29
  • Thanks for responding! I'll figure it out one way or another. Linux was much easier btw. – Mike Q May 04 '13 at 21:25
  • Do you have a suggestion on what I SHOULD do ? Linux has udev, made my life easy. I just had it respond to the event of plugging in a USB harddisk. – Mike Q May 10 '13 at 13:25
  • My answer shows that in Windows it is also enough to respond to an event. I'm not sure what your question still is. – Lars Truijens May 11 '13 at 09:49

1 Answers1

3

You can detect USB device inserts using the Win32_DeviceChangeEvent WMI event. There are other ways, like WM_DEVICECHANGE, but PowerShell already knowns how to handle WMI Events.

$query = "SELECT * FROM Win32_DeviceChangeEvent WHERE EventType = 2"
Register-WMIEvent -Query $query -Action { Write-Host "A device has been inserted"}

Source: here and here

Showing GUI messages could be done using WPF or WinForms.

Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.MessageBox]::Show('Message', 'Title')

Source: here and here

Community
  • 1
  • 1
Lars Truijens
  • 42,837
  • 6
  • 126
  • 143