Solved

console application cannt find ManagementObjectSearcher namespace

Posted on 2007-11-19
4
3,711 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 63

Expert Comment

by:Fernando Soto
ID: 20312912
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 63

Accepted Solution

by:
Fernando Soto earned 50 total points
ID: 20312947
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
ID: 20312964
mega works a treat thanks
0
 
LVL 63

Expert Comment

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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

740 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