WMI 事件 Win32_VolumeChangeEvent 在 Windows XP 上工作吗
我正在尝试使用以下 C# 代码来检测附加/删除事件 USB 大容量存储设备。 我正在使用 Win32_VolumeChangeEvent。
// Initialize an event watcher and subscribe to events that match this query
var _watcher = new ManagementEventWatcher("select * from Win32_VolumeChangeEvent");
_watcher.EventArrived += OnDeviceChanged;
_watcher.Start();
void OnDeviceChanged(object sender, EventArrivedEventArgs args)
{
Console.WriteLine(args.NewEvent.GetText(TextFormat.Mof));
}
问题是这在 Vista 上工作正常,但在 XP 上根本不起作用(没有收到任何事件)。 微软文档说这应该有效(http:// msdn.microsoft.com/en-us/library/aa394516(VS.85).aspx)。 我用谷歌搜索了很长一段时间,发现其他人也有这个问题。 但我还发现了几篇文章,声称这种查询(主要是在 vbscript 中)适用于 XP。 但我找不到微软关于这个问题的一些官方信息,我不敢相信微软在三个服务包中都忽略了这个问题。
所以我的问题是:是否有人在 XP 上成功使用了 Win32_VolumeChangeEvent 或者可以提供链接/解释为什么它不能在 XP 上工作?
I'm trying to use the following c# code to detect the attached/removed event of
usb mass storage devices. I'm using the Win32_VolumeChangeEvent.
// Initialize an event watcher and subscribe to events that match this query
var _watcher = new ManagementEventWatcher("select * from Win32_VolumeChangeEvent");
_watcher.EventArrived += OnDeviceChanged;
_watcher.Start();
void OnDeviceChanged(object sender, EventArrivedEventArgs args)
{
Console.WriteLine(args.NewEvent.GetText(TextFormat.Mof));
}
The problem is that this works fine on Vista but it doesn't work on XP at all (no events received). The Microsoft documentation says that this should work (http://msdn.microsoft.com/en-us/library/aa394516(VS.85).aspx). I googled for this quite a while and found other that have this problem too. But I also found a couple of articles which claim that this kind of query (mostly in vbscript) works with XP. But I cannot find some offical information from microsoft for this issue and I can't believe that Microsoft have overlooked this issue for three service packs.
So my question is: has anybody used the Win32_VolumeChangeEvent with success on XP or can provide a link/explanation why it shouldn't work on XP?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如您可以在自己的链接中阅读的那样,
Win32_VolumeChangeEvent
支持的最低客户端版本是 Windows Vista。 无论如何,按照此处的建议,您可以执行root\\CIMV2
范围内的间隔内的查询。 这是我的代码的示例:As you can read in your own link, the Minimum Supported Client version for
Win32_VolumeChangeEvent
is Windows Vista. Anyway, as suggested here, you can execute a query within interval in theroot\\CIMV2
scope. Here an example from a code of mine:“Win32_VolumeChangeEvent .. 仅在 Windows Server 2003 上找到” - 源
"Win32_VolumeChangeEvent .. is found only on Windows Server 2003" - source