in Education by
I've created a seperate assembly with a class that is intended to be published through wmi. Then I've created a windows forms app that references that assembly and attempts to publish the class. When I try to publish the class, I get an exception of type System.Management.Instrumentation.WmiProviderInstallationException. The message of the exception says "Exception of type 'System.Management.Instrumentation.WMIInfraException' was thrown.". I have no idea what this means. I've tried .Net2.0 and .Net3.5 (sp1 too) and get the same results. Below is my wmi class, followed by the code I used to publish it. //Interface.cs in assembly WMI.Interface.dll using System; using System.Collections.Generic; using System.Text; [assembly: System.Management.Instrumentation.WmiConfiguration(@"root\Test", HostingModel = System.Management.Instrumentation.ManagementHostingModel.Decoupled)] namespace WMI { [System.ComponentModel.RunInstaller(true)] public class MyApplicationManagementInstaller : System.Management.Instrumentation.DefaultManagementInstaller { } [System.Management.Instrumentation.ManagementEntity(Singleton = true)] [System.Management.Instrumentation.ManagementQualifier("Description", Value = "Obtain processor information.")] public class Interface { [System.Management.Instrumentation.ManagementBind] public Interface() { } [System.Management.Instrumentation.ManagementProbe] [System.Management.Instrumentation.ManagementQualifier("Descriiption", Value="The number of processors.")] public int ProcessorCount { get { return Environment.ProcessorCount; } } } } //Button click in windows forms application to publish class try { System.Management.Instrumentation.InstrumentationManager.Publish(new WMI.Interface()); } catch (System.Management.Instrumentation.InstrumentationException exInstrumentation) { MessageBox.Show(exInstrumentation.ToString()); } catch (System.Management.Instrumentation.WmiProviderInstallationException exProvider) { MessageBox.Show(exProvider.ToString()); } catch (Exception exPublish) { MessageBox.Show(exPublish.ToString()); } JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
To summarize, this is the final code that works: Provider class, in it's own assembly: // the namespace used for publishing the WMI classes and object instances [assembly: Instrumented("root/mytest")] using System; using System.Collections.Generic; using System.Text; using System.Management; using System.Management.Instrumentation; using System.Configuration.Install; using System.ComponentModel; namespace WMITest { [InstrumentationClass(System.Management.Instrumentation.InstrumentationType.Instance)] //[ManagementEntity()] //[ManagementQualifier("Description",Value = "Obtain processor information.")] public class MyWMIInterface { //[System.Management.Instrumentation.ManagementBind] public MyWMIInterface() { } //[ManagementProbe] //[ManagementQualifier("Descriiption", Value="The number of processors.")] public int ProcessorCount { get { return Environment.ProcessorCount; } } } /// /// This class provides static methods to publish messages to WMI /// public static class InstrumentationProvider { /// /// publishes a message to the WMI repository /// /// the message text /// the message type public static MyWMIInterface Publish() { // create a new message MyWMIInterface pInterface = new MyWMIInterface(); Instrumentation.Publish(pInterface); return pInterface; } /// /// revoke a previously published message from the WMI repository /// /// the message to revoke public static void Revoke(MyWMIInterface pInterface) { Instrumentation.Revoke(pInterface); } } /// /// Installer class which will publish the InfoMessage to the WMI schema /// (the assembly attribute Instrumented defines the namespace this /// class gets published too /// [RunInstaller(true)] public class WMITestManagementInstaller : DefaultManagementProjectInstaller { } } Windows forms application main form, publishes provider class: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Management; using System.Management.Instrumentation; namespace WMI { public partial class Form1 : Form { public Form1() { InitializeComponent(); } WMITest.MyWMIInterface pIntf_m; private void btnPublish_Click(object sender, EventArgs e) { try { pIntf_m = WMITest.InstrumentationProvider.Publish(); } catch (ManagementException exManagement) { MessageBox.Show(exManagement.ToString()); } catch (Exception exPublish) { MessageBox.Show(exPublish.ToString()); } } } } Test web application, consumer: using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Management.Instrumentation; using System.Management; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ManagementClass pWMIClass = null; pWMIClass = new ManagementClass(@"root\interiorhealth:MyWMIInterface"); lblOutput.Text = "ClassName: " + pWMIClass.ClassPath.ClassName + "
" + "IsClass: " + pWMIClass.ClassPath.IsClass + "
" + "IsInstance: " + pWMIClass.ClassPath.IsInstance + "
" + "IsSingleton: " + pWMIClass.ClassPath.IsSingleton + "
" + "Namespace Path: " + pWMIClass.ClassPath.NamespacePath + "
" + "Path: " + pWMIClass.ClassPath.Path + "
" + "Relative Path: " + pWMIClass.ClassPath.RelativePath + "
" + "Server: " + pWMIClass.ClassPath.Server + "
"; //GridView control this.gvProperties.DataSource = pWMIClass.Properties; this.gvProperties.DataBind(); //GridView control this.gvSystemProperties.DataSource = pWMIClass.SystemProperties; this.gvSystemProperties.DataBind(); //GridView control this.gvDerivation.DataSource = pWMIClass.Derivation; this.gvDerivation.DataBind(); //GridView control this.gvMethods.DataSource = pWMIClass.Methods; this.gvMethods.DataBind(); //GridView control this.gvQualifiers.DataSource = pWMIClass.Qualifiers; this.gvQualifiers.DataBind(); } } }

Related questions

0 votes
    Visual Studio 2005 .Net Framework 2.0 I have the AjaxControlToolkit within my web application bin folder ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 2, 2022 in Education by JackTerrance
0 votes
    I have a mystery on my hands. I am trying to learn managed C++ coming from a C# background and ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    Having a problem getting a TreeView control to display node images. The code below works sometimes but fails ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    Is anyone using the Obout controls in C# .Net? How would you rate these controls, especially the Grid ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    Cognizant Bulk Hiring Freshers and Experienced 2023| CTC 5 to 15 LPA | Apply Now...
asked Feb 27, 2023 in Technology by Editorial Staff
0 votes
    I would like to know how to unload an assembly that is loaded into the main AppDomain. I have the ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    I would like to know how to unload an assembly that is loaded into the main AppDomain. I have the ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    I just finished watching the Google clean code video on YouTube (see link, first article) about removing if ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 7, 2022 in Education by JackTerrance
0 votes
    I just finished watching the Google clean code video on YouTube (see link, first article) about removing if ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 6, 2022 in Education by JackTerrance
0 votes
    I just finished watching the Google clean code video on YouTube (see link, first article) about removing if ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 5, 2022 in Education by JackTerrance
0 votes
    I just finished watching the Google clean code video on YouTube (see link, first article) about removing if ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 5, 2022 in Education by JackTerrance
0 votes
    I just finished watching the Google clean code video on YouTube (see link, first article) about removing if ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 5, 2022 in Education by JackTerrance
0 votes
    I want create expression with reflection in c#. I am target script is: using (var service = new ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 14, 2022 in Education by JackTerrance
0 votes
    What is the .vs folder used for exactly? It gets created at the base folder of my solution. I ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    Here is the example: if(value != ageValue) { ageValue = value; } I mean, if we assign the value ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
...