none
WMI - Event registration failed (Access denied) RRS feed

  • Question

  • Hi,

     

     I am getting Access Denied error when i try to register events on Windows 2008 Hypervisor remotely from a Windows 7 machine. 

    Here i am registering events for poweron of VMs.

    This code works fine when both my machines are in domain. I moved them(both Win 2008 machine and Win 7 machine) to Workgroup, then i am getting Access denied error.

    But all the other WMI calls are working fine(like get list of VMs).

                   ManagementScope scope = GetScope(hypervisorName, "virtualization");
                    WqlEventQuery query = new WqlEventQuery();
                    query.EventClassName = "__InstanceModificationEvent";
                    query.WithinInterval = new TimeSpan(0, 0, 5);
                    query.Condition =
                        "TargetInstance ISA 'Msvm_ComputerSystem' AND TargetInstance.EnabledState = 2";
                    watcherPowerOn = new ManagementEventWatcher(scope, query);               
                    watcherPowerOn.EventArrived += new EventArrivedEventHandler(watcher_EventArrived_RegisterVMPowerOnEvent);
                    watcherPowerOn.Start(); <- here it throws exception!

    Error: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

     

    Any help is appreciated.

     

    Regards,

    Hari

    Wednesday, June 6, 2012 1:36 PM

All replies

  • Hi, 

    Same issue has been discussed over here

    http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/7bb7c673-c153-4540-a3fb-36fe99fde196


    If this post answers your question, please click "Mark As Answer". If this post is helpful please click "Mark as Helpful".

    • Proposed as answer by Pantelis44999 Wednesday, June 6, 2012 5:49 PM
    Wednesday, June 6, 2012 5:00 PM
  • Hi,

    Thanks for the replay,

    I tried the steps that is mentioned in the link. But doesnt worked.

    I am pasting my code here.

    My environment:

    Hypervisor : Windows 2008 (in WORKGROUP)

    Client: Windows 7 (WORKGROUP) <- from here i will invoke code

    class

    Program

    {

    static void Main(string[] args)

    {

    ManagementScope scope = GetScope("<IP>", "virtualization");

    WqlEventQuery query = new WqlEventQuery();

    query.EventClassName =

    "__InstanceModificationEvent";

    query.WithinInterval =

    new TimeSpan(0, 0, 5);

    query.Condition =

    "TargetInstance ISA 'Msvm_ComputerSystem' AND TargetInstance.EnabledState = 3 AND TargetInstance.ProcessID = 0";

    ManagementEventWatcher watcherPowerOff = new ManagementEventWatcher(scope, query);

    watcherPowerOff.Start();  <- here am getting error

    watcherPowerOff.EventArrived +=

    new EventArrivedEventHandler(watcherPowerOff_EventArrived);

    }

    static void watcherPowerOff_EventArrived(object sender, EventArrivedEventArgs e)

    {

    throw new NotImplementedException();

    }

    private static ManagementScope GetScope(string hypervisorName, string wmiScope)

    {

    try

    {

    ManagementScope scope =

    new ManagementScope(string.Format(@"\\{0}\root\{1}", hypervisorName, wmiScope));

    scope.Options.EnablePrivileges =

    true;

    scope.Options.Username =

    "<Hostname>\\Administrator";

    scope.Options.Password =

    "<Password>";

    scope.Options.Authentication =

    AuthenticationLevel.Default;

    scope.Options.Impersonation =

    ImpersonationLevel.Default;

    scope.Connect();

    return scope;

    }

    catch (ManagementException ex)

    {

    throw ex;

    }

    catch (Exception ex)

    {

    throw ex;

    }

    }

    }

    Thursday, June 7, 2012 1:28 PM
  • I am able to solve this by moving my Windows 7 machine to Windows 2008 server.

    After moving this to Win 2008, i faced an RPC unavailable error!! I was able to solve this by adding entry in the etc > host file.

     

    I am still not able to find why this doesnt work with Win 2k8! Any idea?

     

    -Hari

    Monday, June 11, 2012 9:20 AM