Accesso al provider WMI a livello di programmazioneAccessing the WMI Provider Programmatically

Cenni preliminari sul provider WMIWMI Provider Overview

Lo spazio dei nomi usato per ottenere informazioni su Reporting ServicesReporting Services negli esempi di codice descritti in questo argomento è System.Management, disponibile in MicrosoftMicrosoft .NET Framework.NET Framework.The namespace used to obtain information about Reporting ServicesReporting Services in the code samples shown in this topic is the System.Management namespace, found in the MicrosoftMicrosoft .NET Framework.NET Framework. Lo spazio dei nomi System.Management offre un set di classi di codice gestito tramite il quale le applicazioni .NET Framework.NET Framework possono accedere alle informazioni di gestione e modificarle.The System.Management namespace provides a set of managed code classes through which .NET Framework.NET Framework applications can access and manipulate management information. Per altre informazioni sull'uso delle classi WMI di Reporting Services tramite lo spazio dei nomi System.Management, vedere l'argomento relativo all'accesso alle informazioni di gestione con System.Managment in MicrosoftMicrosoft .NET Framework.NET Framework SDK.For more information on using the Reporting Services WMI classes using the System.Management namespace, see "Accessing Management Information with System.Managment" in the MicrosoftMicrosoft .NET Framework.NET Framework SDK.

Individuazione di un'istanza del server di reportFinding a Report Server Instance

Il metodo migliore per individuare le informazioni nelle installazioni del server di report consiste nell'eseguire un'enumerazione nella raccolta di istanze WMI.The preferred way of finding information on your report server installations is to enumerate through the WMI instance collection. Nell'esempio seguente viene illustrato come individuare le proprietà in ogni istanza del server di report creando una raccolta ed eseguendo un ciclo al suo interno per visualizzare le proprietà.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.

Imports System  
Imports System.Management  
Imports System.IO  

Module Module1  
    Sub Main()  
        Const WmiNamespace As String = "\\<ServerName>\root\Microsoft\SqlServer\ReportServer\<InstanceName>\v10\Admin"  
        Const WmiRSClass As String = _  
           "\\<ServerName>\root\Microsoft\SqlServer\ReportServer\<InstanceName>\v13\admin:MSReportServer_ConfigurationSetting"  

        Dim serverClass As ManagementClass  
        Dim scope As ManagementScope  
        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 Is Nothing Then Throw New Exception("No class found")  

        'Loop through the instances of the server class.  
        Dim instances As ManagementObjectCollection = serverClass.GetInstances()  
        Dim instance As ManagementObject  
        For Each instance In instances  
            Console.Out.WriteLine("Instance Detected")  
            Dim instProps As PropertyDataCollection = instance.Properties  
            Dim prop As PropertyData  
            For Each prop In instProps  
                Dim name As String = prop.Name  
                Dim val As Object = prop.Value  
                Console.Out.Write("Property Name: " + name)  
                If val Is Nothing Then  
                    Console.Out.WriteLine("     Value: <null>")  
                Else  
                    Console.Out.WriteLine("     Value: " + val.ToString())  
                End If  
            Next  
        Next  

        Console.WriteLine("--- Press any key ---")  
        Console.ReadKey()  

    End Sub  
End Module  
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>\v13\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();  
    }  
}  

Vedere ancheSee Also

Accedere al provider WMI per Reporting Services Access the Reporting Services WMI Provider
File di configurazione RsReportServer.configRsReportServer.config Configuration File