Solved

console application cannt find ManagementObjectSearcher namespace

Posted on 2007-11-19
4
3,692 Views
Last Modified: 2013-12-17
Hi everyone im trying to write a console application to find the free space etc on a hard drive however it wont run but keeps telling me that the namespace cannt be found.  my code is below along with the error

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management;

namespace serverInfo
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("starting ok");
            ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from win32_share");
            Console.WriteLine("object created ok");
        }
    }
}


Error      2      The type or namespace name 'ManagementObjectSearcher' could not be found (are you missing a using directive or an assembly reference?)      C:\Documents and Settings\AndrewSlaughter\Local Settings\Application Data\Temporary Projects\serverInfo\Program.cs      14      53      serverInfo
0
Comment
Question by:andrew67
  • 3
4 Comments
 
LVL 62

Expert Comment

by:Fernando Soto
Comment Utility
Not only do you need this line of code.

using System.Management;

But you need to add a Reference to the System.Management.dll library.
0
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 50 total points
Comment Utility
To add the library follow these steps.

Open the Solution Explorer window
Right click on the project name at the top of the tree view.
Click on Add Reference...
Select the .Net tab if it is not already selected.
Scroll down till you get to System.Management under Component Name and click on it to select it.
Click on the OK button.

It should work now.
0
 
LVL 3

Author Comment

by:andrew67
Comment Utility
mega works a treat thanks
0
 
LVL 62

Expert Comment

by:Fernando Soto
Comment Utility
Not a problem, glad I was able to help. ;=)
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now