Export (0) Print
Expand All

Accessing the WMI Provider Programmatically

This topic is under construction.

The namespace used to obtain information about Reporting Services in the code samples shown in this topic is the System.Management namespace, found in the Microsoft .NET Framework. The System.Management namespace provides a set of managed code classes through which .NET Framework applications can access and manipulate management information. For more information on using the Reporting Services WMI classes using the System.Management namespace, see "Accessing Management Information with System.Managment" in the Microsoft .NET Framework SDK.

The preferred way of finding information on your report server installations is to enumerate through the WMI instance collection. The example below shows how to find properties on every report server instance by creating a collection, and looping through the collection to display the properties.

using System;
using System.Management;
using System.IO;
[assembly: CLSCompliant(true)]

class Class1
{
    [STAThread]
    static void Main(string[] args)
    {
        const string WmiNamespace = @"\\<ServerName>\root\Microsoft\SqlServer\ReportServer\<InstanceName>\v10\Admin";
        const string WmiRSClass =
          @"\\<ServerName>\root\Microsoft\SqlServer\ReportServer\<InstanceName>\v10\admin:MSReportServer_ConfigurationSetting";
        ManagementClass serverClass;
        ManagementScope scope;
        scope = new ManagementScope(WmiNamespace);

        // Connect to the Reporting Services namespace.
        scope.Connect();
        // Create the server class.
        serverClass = new ManagementClass(WmiRSClass);
        // Connect to the management object.
        serverClass.Get();
        if (serverClass == null)
            throw new Exception("No class found");

        // Loop through the instances of the server class.
        ManagementObjectCollection instances = serverClass.GetInstances();

        foreach (ManagementObject instance in instances)
        {
            Console.Out.WriteLine("Instance Detected");
            PropertyDataCollection instProps = instance.Properties;
            foreach (PropertyData prop in instProps)
            {
                string name = prop.Name;
                object val = prop.Value;
                Console.Out.Write("Property Name: " + name);
                if (val != null)
                    Console.Out.WriteLine("     Value: " + val.ToString());
                else
                    Console.Out.WriteLine("     Value: <null>");
            }
        }
        Console.WriteLine("\n--- Press any key ---");
        Console.ReadKey();
    }
}

Community Additions

ADD
Show:
© 2014 Microsoft