none
ManagementOperationObserver causes access denied error RRS feed

  • Question

  • Hi,

    I am trying to use a ManagementOperationObserver with a ManagementObjectSearcher.Get() call but I am getting an access denied error. If I make the same call without the ManagementOperationObserver it works fine.

    Sample code:

     

    String systemQuery = "SELECT * FROM Win32_Service";

    ManagementOperationObserver serviceQuery = new ManagementOperationObserver();

    serviceQuery.ObjectReady += new ObjectReadyEventHandler(serviceQuery_ObjectReady);

    serviceQuery.Completed += new CompletedEventHandler(serviceQuery_Completed);

    try

    {

    ObjectQuery oQuery = new ObjectQuery(systemQuery);

    ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(cmScope, oQuery);

    oSearcher.Get(serviceQuery);

    }

    catch (Exception ex)

    {

    Console.WriteLine("ERROR: " + ex.Message);

    }


    Thanks in advance
    Steve
    • Edited by SThomps Monday, September 12, 2011 1:30 PM
    • Edited by Paul Zhou Wednesday, September 14, 2011 2:37 AM font size
    Monday, September 12, 2011 1:26 PM

Answers

  • I figured this one out, it was down to DCOM permissions between machines in different domains.

    Thanks
    Steve

    • Marked as answer by Paul Zhou Monday, October 3, 2011 2:44 AM
    Friday, September 30, 2011 12:39 PM

All replies

  •  

    Hi,

     

    May I know which code line throws the error? What is the detail message of the error?

    Could you please show us code snippet that does not use ManagementOperationObserver?

     

    I look forward to hearing from you.

    Have a nice day.


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, September 14, 2011 2:54 AM
  • Hi Paul,

    The oSearcher.Get(serviceQuery) line throws the error. If I call oSearcher.Get() it works fine.

    The detail of the error is:

    System::Exception^ = 0x000000000449db88 { "Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"}

    Thanks
    Steve

    Monday, September 26, 2011 8:46 AM
  • Hi,

    In your code , you need to pass some authentication details for accessing the resources. I have checked your code, it didn't generate exception for the local machine, however while accessing the resource for remote machines it threw an exception. I have modified your code module, check it and let me know if it works

     try {
                    ManagementScope  cmScope= new ManagementScope ();
                   
                    cmScope .Options .Username ="";
                    cmScope.Options.Password = "";
                    cmScope.Connect();
                    ObjectQuery oQuery = new ObjectQuery(systemQuery); 
                    ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(cmScope, oQuery); 
                    oSearcher.Get(serviceQuery);
                }
                catch (Exception ex)
                { 
                    Console.WriteLine("ERROR: " + ex.Message);
                }
    

    Hope it helps.Looking forward to hear from you.

    Regards,
    A.Murugan

     


    If it solved your problem,Please click "Mark As Answer" on that post and "Mark as Helpful". Happy Programming!
    • Proposed as answer by Paul Zhou Wednesday, September 28, 2011 5:28 AM
    • Unproposed as answer by SThomps Thursday, September 29, 2011 9:25 PM
    Monday, September 26, 2011 9:36 AM
  • Hi,

    Apologies, I did not include the code fragment for my ManagementScope. I'm already setting the username and password to the domain administrator account.

    I can perform other operations without an issue, it's only when I use the ManagementOperationObserver with the ManagementObjectSearcher that I see the Acces Denied error.

    Thanks
    Steve

    Thursday, September 29, 2011 3:26 PM
  • Based on A.Murugan's post I did another test.

    The ManagementOperationObserver works if the code runs on the machine itself, the access denied error is thrown if you try to use a ManagementOperationObserver with a remote machine.

    Is there any method to get this working with a remote machine?

    Thanks
    Steve

    Thursday, September 29, 2011 4:18 PM
  • Hi steve,

    I think the issue is related to the privilege to access remote machine, you need to ensure that the user account has right to login to the remote machine and implement WMI.

    Some code projects show how to implement it:

    Manage Processes on Remote Machine

    Windows Management Instrumentation (WMI) Implementation


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, September 30, 2011 6:59 AM
  • Hi Paul,

    I can successfully perform WMI searches and create new class instances the only operation that fails is a search with the ManagementOperationObserver. I'm authenticating as a local administrator and the account has explicit rights to perform all WMI operations.

    Both of those samples use the observer with an invokeMethod call, do you have any working examples using a ManagementObjectSearcher with an observer?

    Thanks
    Steve

    Friday, September 30, 2011 9:21 AM
  • I figured this one out, it was down to DCOM permissions between machines in different domains.

    Thanks
    Steve

    • Marked as answer by Paul Zhou Monday, October 3, 2011 2:44 AM
    Friday, September 30, 2011 12:39 PM