c# 4.0 - Not found exception When start the ManagementEventWatcher -
not found exception times while starting maagementeventwatcher
my code sample given below :
try { string scopepath = @"\\.\root\default"; managementscope managementscope = new managementscope(scopepath); wqleventquery query = new wqleventquery( "select * registrykeychangeevent " + "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(); } }
exception:
not found @ system.management.managementexception.throwwithextendedinfo(managementstatus errorcode) @ system.management.managementeventwatcher.start() @ mtts.labx.rocklog.appservice.usbmonitor.addregistrywatcherhandler()]
note : checked in registry,folder , files found.
managementexception "not found" thrown when there not match in wql query. maybe have specified wrong keypath or keypath no longer available.