gpt4 book ai didi

c#-4.0 - 启动 ManagementEventWatcher 时未发现异常

转载 作者:行者123 更新时间:2023-12-02 21:40:58 24 4
gpt4 key购买 nike

启动 MaagementEventWatcher 时有时会出现未发现异常

我的代码示例如下:

 try
{
string scopePath = @"\\.\root\default";
ManagementScope managementScope = new ManagementScope(scopePath);
WqlEventQuery query =
new WqlEventQuery(
"SELECT * FROM RegistryKeyChangeEvent WHERE " + "Hive = 'HKEY_LOCAL_MACHINE'"
+ @"AND KeyPath = 'HARDWARE\\DEVICEMAP\\SERIALCOMM'");
registryWatcher = new ManagementEventWatcher(managementScope, query);
registryWatcher.EventArrived += new EventArrivedEventHandler(SerialCommRegistryUpdated);

registryWatcher.Start();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
if (registryWatcher != null)
{
registryWatcher.Stop();
}
}

异常:

  Not found
at System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode)
at System.Management.ManagementEventWatcher.Start()
at MTTS.LabX.RockLog.AppService.USBMonitor.AddRegistryWatcherHandler()]

注意:我检查了注册表,找到了文件夹和文件。

最佳答案

当 WQL 查询中不匹配时,将引发 ManagementException“未找到”。也许您指定了错误的 KeyPath 或者 KeyPath 不再可用。

关于c#-4.0 - 启动 ManagementEventWatcher 时未发现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16212561/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com