program throws not found or not supported exception while using Managment Event

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • diyasher
    New Member
    • Jul 2007
    • 5

    program throws not found or not supported exception while using Managment Event

    hello

    while running program that use system.manageme nt namespace and holds management event the exception throws "not found" and some time "not supported" unhandled management exception on management event start() method, i am using windows xp professional sp2, the sample code is

    class Program
    {
    public static void Main(string[] args)
    {
    ManagementScope scope = new ManagementScope ("root\\default ");
    WqlEventQuery q = new WqlEventQuery() ;
    q.EventClassNam e = "RegistryTreeCh angeEvent";
    q.Condition = @"Hive='HKEY_LO CAL_MACHINE' and RootPath='Softw are\\Policies'" ;

    using (ManagementEven tWatcher w = new ManagementEvent Watcher(scope,q ))
    {
    w.EventArrived += new EventArrivedEve ntHandler(EvLog EventArrived);
    w.Start(); //exception throws on this line
    Console.ReadLin e(); // Block this thread for test purposes only....
    w.Stop();

    }
    }
    static void EvLogEventArriv ed(object sender, EventArrivedEve ntArgs e)
    {
    //Get the Event object and display it
    foreach (PropertyData pd in e.NewEvent.Prop erties)
    {
    //if (pd.Name.ToLowe r() == "rootpath")
    Console.WriteLi ne("{0} = {1}", pd.Name, pd.Value);
    }
    }
    }


    these types of program running correctly when i am using xp home sp2, but when change operating system these program fail to run..

    plz help me if u have any idea i am very tense bcoz these exception is throw in my final project.

    thanks aton
    bye
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Where does the exception occur? Like on what call?

    What system are you trying to run it on?
    I ran it fine on XP pro sp2, perhaps you must have sp2 for it to run?

    Comment

    • diyasher
      New Member
      • Jul 2007
      • 5

      #3
      i am running on windows xp professional sp2.
      exception occur on statement
      w.start();

      Originally posted by Plater
      Where does the exception occur? Like on what call?

      What system are you trying to run it on?
      I ran it fine on XP pro sp2, perhaps you must have sp2 for it to run?

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Yeah, sorry, I see that now.

        Well I looked up and saw:
        .NET Framework Security
        Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.

        So maybe you need to change permisions?

        Comment

        • hbxtlhx
          New Member
          • Sep 2007
          • 10

          #5
          using (ManagementEven tWatcher w = new ManagementEvent Watcher(scope,q ))
          {
          ....
          }


          w is disposed!
          make it global!

          for example:

          private ManagementEvent Watcher w;

          ...

          w=w ManagementEvent Watcher(scope,q );
          w....

          Comment

          Working...