Select statement for ManagementObjectSearcher will not work correctly

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
Computer:    
Description:
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)
{
}
LVL 2
NewMom2BrandonAsked:
Who is Participating?
 
wishguitarConnect With a Mentor Commented:
Try

string sDriveFindings = "select * from Win32_LogicalDisk where DriveType = " +  dType.ToString();
0
 
NewMom2BrandonAuthor Commented:
Worked Great Thank you!!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.