none
How do I enable a WMI function to run in my Visual Studio Application?

    Question

  • To be clearer, I want to have an instance check for hardware issues when my application says so.  I want to pull that error info from WMI.  I am doing this for testing purposes.  
    Tuesday, March 08, 2016 6:10 PM

Answers

  • Hi,

    Which language are you using?
    [C#]

    using System.Management;
    // -- WMI(Windows Management Instruction)[Reference : adding System.Management]

    private void button1_Click(object sender, EventArgs e)

    {
    ManagementObjectSearcher oMS = new ManagementObjectSearcher(); ManagementObjectCollection oMC; string sMsgStr = ""; // oMS.Query.QueryString="SELECT * FROM Win32_Process"; oMC= oMS.Get(); // foreach (ManagementObject oMO in oMC) { sMsgStr = sMsgStr & oMO["Description"].ToString() & ":" & oMO["ProcessId"].ToString() & "\n"; } MessageBox.Show(sMsgStr); }

    [VB.Net]

    Imports System.Management ' -- WMI(Windows Management Instruction)[Reference : adding System.Management]

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim Searcher As New ManagementObjectSearcher() Dim PrcSrc As ManagementObjectCollection Dim Prc As ManagementObject Dim MesStr As String ' Searcher.Query.QueryString = "SELECT * FROM Win32_Process" PrcSrc = Searcher.Get ' For Each Prc In PrcSrc MesStr = MesStr & Prc("Description") & ":" & Prc("ProcessId").ToString() & vbCrLf Next ' MsgBox(MesStr) End Sub

    Regards.

    Wednesday, March 09, 2016 11:02 PM