我需要禁止大容量存储设备的自动播放。这需要通过在后台运行的服务/守护程序以编程方式实现。
我知道它可以通过打开一个窗口并处理窗口发送的“queryCancelAutoPlay”消息的应用程序来完成。
这可以在没有 GUI 的情况下完成吗?我有需要禁用自动播放的设备的 guid/pid/vid。
当然。您可以创建一个仅消息窗口。这给了你一个没有那些烦人的 WM_PAINT 消息等的 HWND。另一种方法是使用 COM,IQueryCancelAutoplay
有一个注册表项控制自动运行:
HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer
这可以设置为在特定设备类型上禁用自动运行,来自technet:
NoDriveTypeAutoRun
Value Meaning
0x1 Disables Autoplay on drives of unknown type.
0x4 Disables Autoplay on removable drives.
0x8 Disables Autoplay on fixed drives.
0x10 Disables Autoplay on network drives.
0x20 Disables Autoplay on CD-ROM drives.
0x40 Disables Autoplay on RAM drives.
0x80 Disables Autoplay on drives of unknown type.
0xFF Disables Autoplay on all types of drives.