Link to home
Start Free TrialLog in
Avatar of NewMom2Brandon
NewMom2Brandon

asked on

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)
{
}
ASKER CERTIFIED SOLUTION
Avatar of wishguitar
wishguitar

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 NewMom2Brandon
NewMom2Brandon

ASKER

Worked Great Thank you!!!