Click here to Skip to main content
15,892,161 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
this is my code it gives error . it could not found ManagementObjectSearcher class from using System.Management;

my code

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Management;
using System.Collections.Generic;
using System.Management;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\WMI", "SELECT * FROM MSStorageDriver_ATAPISmartData");

//here ManagementObjectSearcher not found

                foreach (ManagementObject queryObj in searcher.Get())
                {
                    if (queryObj["VendorSpecific"] != null)
                    {
                        byte[] arrVendorSpecific = (byte[])(queryObj["VendorSpecific"]);
                        string temp = arrVendorSpecific[115].ToString();
                    }
                }
            }
            catch (Exception)
            {

                throw;
            }

        }
    }
}


Please help me to slove this problem.
Posted
Updated 11-Mar-19 0:18am
v4
Comments
[no name] 27-Aug-13 7:27am    
Check again that you added a reference to System.Management.dll
[no name] 27-Aug-13 7:30am    
i could not found System.Management.dll i can found only System.Management.Instrumentation and System.Management;
Member 11713900 6-Aug-15 16:24pm    
go to solution explorer and rightClick on refrences and add refrence , then choose the system.management and click ok . then type using system.management;
now u can use this class in your app !
[no name] 27-Aug-13 7:31am    
in my code i also add System.Management
PugaliaSushil 10-Aug-15 3:25am    
@Archit Patel
Thanks, this solved my issue.

Right Click Your Project=> Add Reference=> Framework=> Tick 2 item ( System.Management and
System.Management.Instrumentation). And Then Click Ok. Good Luck!
 
Share this answer
 
managementobject-class-not-showing-up-in-system-management-namespace[^]

it's a slimier kind of issue..give a try to the solutions..
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900