Accès au fournisseur WMI par programmationAccessing the WMI Provider Programmatically

Vue d'ensemble du fournisseur WMIWMI Provider Overview

L'espace de noms utilisé pour obtenir des informations sur Reporting ServicesReporting Services dans les exemples de code contenus dans cette rubrique est System.Management , qui est issu du 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. L'espace de noms System.Management fournit un jeu de classes de code managé par le biais desquelles les applications .NET Framework.NET Framework peuvent accéder à des informations de gestion et les manipuler.The System.Management namespace provides a set of managed code classes through which .NET Framework.NET Framework applications can access and manipulate management information. Pour plus d'informations sur l'utilisation des classes WMI de Reporting Services à l'aide de l'espace de noms System.Management , consultez « Accès aux informations de gestion avec System.Management » dans le Kit de développement logiciel (SDK) MicrosoftMicrosoft .NET Framework.NET Framework .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.

Recherche d'une instance de serveur de rapportsFinding a Report Server Instance

La méthode privilégiée pour rechercher des informations sur vos installations de serveur de rapports consiste à énumérer la collection d'instances WMI.The preferred way of finding information on your report server installations is to enumerate through the WMI instance collection. L'exemple suivant indique comment rechercher des propriétés sur chaque instance de serveur de rapports en créant une collection et en effectuant une boucle dans la collection pour afficher les propriétés.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();  
    }  
}  

Voir aussiSee Also

Accès au fournisseur WMI de Reporting Services Access the Reporting Services WMI Provider
Fichier de Configuration RsReportServer.config RsReportServer.config Configuration File