unable to get installed software details of vm machine of azure using System.Management

0

My requirement is to get installed software details of vm machine of azure and store the details in db. but when I try to get the details using System.Management class I am getting the below error

System.Runtime.InteropServices.COMException: 'The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)'

below is my sample code I am using to get the software details

 string SoftwareQuery = "SELECT * FROM Win32_Product";
        ConnectionOptions connection = new ConnectionOptions();



            connection.Username = "bla bla";
            connection.Password = "Password";

        connection.EnablePrivileges = true;
        connection.Impersonation = ImpersonationLevel.Impersonate;

        ManagementScope managementScope = new ManagementScope(@"\\xxxx.xxxx.cloudapp.azure.com:3389\root\CIMV2", connection);
        managementScope.Path = ManagementPath.DefaultPath;
        managementScope.Connect();


        ObjectQuery queryObj = new ObjectQuery(SoftwareQuery);
        ManagementObjectSearcher searcher = new ManagementObjectSearcher(managementScope, queryObj);

        foreach (ManagementBaseObject managementObj in searcher.Get())
        {

           //get the software list here 

        }

Note: The above code is working on intranet properly

Please let me know anyone have solution on this.

c#
azure
azure-virtual-machine
asked on Stack Overflow Nov 22, 2018 by Vikas Sonichya • edited Feb 18, 2019 by Md Farid Uddin Kiron

1 Answer

0

It might be related to the Windows Management Instrumentation service being in a stopped state. Take a look at Starting and Stopping the WMI Service.

Hope it helps!

answered on Stack Overflow Nov 22, 2018 by Itay Podhajcer

User contributions licensed under CC BY-SA 3.0