Link to home
Start Free TrialLog in
Avatar of andrew67
andrew67

asked on

console application cannt find ManagementObjectSearcher namespace

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
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

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.
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of andrew67
andrew67

ASKER

mega works a treat thanks
Not a problem, glad I was able to help. ;=)