通过 USB 或其他方式连接新驱动器时获取通知 (C#)
我需要检测新驱动器何时通过 USB 端口、火线端口等插入 Windows 系统。我知道 WM_DEVICECHANGE 消息,但这需要打开一个窗口才能使用它。有没有办法在 C# 中创建一个后台进程来检测何时插入新驱动器?
背景信息:我想编写这个应用程序来从公司可移动驱动器中删除蠕虫。常规防病毒软件无法删除它。我们有一个可以删除蠕虫的脚本,但它必须手动运行,这不足以遏制病毒的爆发。
I need to detect when a new drive is plugged into a Windows system through a USB port, firewire port, etc. I am aware of the WM_DEVICECHANGE message, but this requires a window to be open in order to use it. Is there a way to create a background process in C# that detects when new drives are plugged in?
Background info: I am wanting to write this app to remove a worm from company removable drives. Regular antivirus software is failing to removing it. We have a script that will remove the worm, but it must be run manually, which is not good enough to contain the outbreak.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Windows 服务 应该可以解决问题
尝试重新设计 CodeProject DriveDetector 作为一项服务,您应该拥有您需要的东西
A windows service should do the trick
Try reworking the CodeProject DriveDetector as a service and you should have what you need
您需要订阅
RegisterDeviceNotification
,并将其绑定到服务状态句柄。另请参阅 http:// Social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/9ae4478a-1133-44ba-8a1c-3e4be3856e37。我不太确定如何实现这个,已经很久了。
You will need to subscribe to
RegisterDeviceNotification
, and bind it to a service status handle. See also http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/9ae4478a-1133-44ba-8a1c-3e4be3856e37.I'm not quite sure how to implement this, has been a long time ago.
这篇博文展示了如何处理系统事件,https://web.archive.org/web/1/http://blogs.techrepublic%2ecom%2ecom/howdoi/?p=135 也许您可以将它用于您想要的活动想要处理
This blogpost show how to handle system events, https://web.archive.org/web/1/http://blogs.techrepublic%2ecom%2ecom/howdoi/?p=135 maybe you can use it for the event that you want to handle
您可以创建隐藏窗口或运行服务,因为它应该与窗口句柄或服务状态句柄一起使用。
You may create a hidden window or run a service as it should work with a window handle or a service status handle.