Problem in RegistryKeyChangeEvent

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sakthikumarb
    New Member
    • Sep 2008
    • 19

    Problem in RegistryKeyChangeEvent

    Hi,

    during Registry key change event ,if i give wrong keypath .it saying invalid query.if i give existing keypath then code is executing correctly ...

    my doubt is ,how the event registration is happening in case of Registry key change.
    why it saying invalid query in case of wrong input to the keypath.eventho ugh the keypath should accept a string ..any reference to the same..
    Code:
    strQuery = " SELECT * FROM RegistryKeyChan geEvent WHERE
    KeyPath = 'asdf'"
    WqlEventQuery WqlQuery = new WqlEventQuery(s trQuery);
    watcher = new ManagementEvent Watcher(wmiMgmt Scope, WqlQuery);
    watcher.EventAr rived += Eventhandler;
    watcher.Start() ;
    Regards,
    Sakthi
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    How can you watch a change on something that doesn't exist? That would not make sense. It sounds like it is functioning correctly.

    Comment

    • tlhintoq
      Recognized Expert Specialist
      • Mar 2008
      • 3532

      #3
      Originally posted by Plater
      How can you watch a change on something that doesn't exist? That would not make sense. It sounds like it is functioning correctly.
      Agreed. Can't watch what doesn't exist. Its easy to code for a perfect world. The tough part is to presume everyone is wrong including the input and the state of the machine.

      You have to add lots of range checking and presumption validation.

      [suedo code]
      if (RegKey exists) WatchRegKey
      else { messagebox the user they are a dork }

      No different than setting up a FileSystemWatch er. If the directory doesn't exist you can't watch it for changes, so either check it exists, or make it before you watch it. If it already exists when you make it, then no harm done.

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        You could maybe attempt to watch the parent of where the key *should* be for changes then? The creation of the key in question should register in its parent's change event right?

        Comment

        Working...