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.M anagementE xception: Invalid query
at System.Management.Manageme ntExceptio n.ThrowWit hExtendedI nfo(Manage mentStatus errorCode)
at System.Management.Manageme ntObjectEn umerator.M oveNext()
at c:\..bla bla\drivespace.cs:line 52
/// <Remarks> Get DriveType. </Remarks>
XmlNode xmlNodeChild = xmlNode.SelectSingleNode(T AGS.DriveT ypeMonitor ed);
double dType = Convert.ToDouble(xmlNodeCh ild.InnerT ext);
************************** ********** ********** ***
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(s DriveNames pace, sDriveFindings );
ManagementObjectCollection Collection = DriveSearcher.Get(); This is line 52***
foreach (ManagementObject Item in Collection)
{
}
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.M
at System.Management.Manageme
at System.Management.Manageme
at c:\..bla bla\drivespace.cs:line 52
/// <Remarks> Get DriveType. </Remarks>
XmlNode xmlNodeChild = xmlNode.SelectSingleNode(T
double dType = Convert.ToDouble(xmlNodeCh
**************************
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(s
ManagementObjectCollection
foreach (ManagementObject Item in Collection)
{
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER