Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

console application cannt find ManagementObjectSearcher namespace

Posted on 2007-11-19
4
Medium Priority
?
3,729 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 64

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 64

Accepted Solution

by:
Fernando Soto earned 200 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 64

Expert Comment

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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

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…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Loops Section Overview
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

824 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