Select statement for ManagementObjectSearcher will not work correctly

Posted on 2005-04-13
Last Modified: 2010-08-05
I am trying to do a ManagementObjectSearcher search. I am using an XML file for some of the data which can be changed on the fly without having to rebuild the code everytime

This is the error I get
Event Type:     Error
Event Source:     DriveSpace
Event Category:     None
Event ID:     0
Date:          4/13/2005
Time:          12:07:46 PM
User:          N/A
Failed to get Drive Space information from Operating System.System.Management.ManagementException: Invalid query
   at System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode)
   at System.Management.ManagementObjectEnumerator.MoveNext()
   at  c:\..bla bla\drivespace.cs:line 52

/// <Remarks> Get DriveType. </Remarks>
XmlNode xmlNodeChild = xmlNode.SelectSingleNode(TAGS.DriveTypeMonitored);
double dType = Convert.ToDouble(xmlNodeChild.InnerText);
As long as I have a actual number in the search like this "from Win32_LogicalDisk where DriveType = 3"
It will work but when I put in the dType I get the error. I would really like to
Leave this as something that is done on the fly..If you have any help please let me know

string sDriveFindings = "select * from Win32_LogicalDisk where DriveType = dType";
/// <Remarks>retrieves a collection of management objects based on query</Remarks>
     ManagementObjectSearcher DriveSearcher = new
       ManagementObjectSearcher(sDriveNamespace, sDriveFindings );
ManagementObjectCollection Collection = DriveSearcher.Get(); This is line 52***
foreach (ManagementObject Item in Collection)
Question by:NewMom2Brandon
    LVL 3

    Accepted Solution


    string sDriveFindings = "select * from Win32_LogicalDisk where DriveType = " +  dType.ToString();
    LVL 2

    Author Comment

    Worked Great Thank you!!!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Article by: Ivo
    C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    761 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

    11 Experts available now in Live!

    Get 1:1 Help Now