Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Casting & WMI Problem 1

Status
Not open for further replies.

JBravo

Programmer
Mar 21, 2002
12
IE
Hi all,
I keep getting a casting exception in the following section of code. I can't seem to convert from the object to int.
Also,
is there any way of getting the first element from queryCollection other than having to enmerate through it?
Thanks for yeer help,
J.

Code:
ManagementObjectCollection queryCollection = query.Get();	
	int tempint;
	Object obj;
foreach(ManagementObject mo in queryCollection)
	{
				
	      obj = mo.InvokeMethod("Terminate", null);
here---------->tempint = (int) obj;
				return tempint;
			}
 
The best way to do conversions is to utilize the Convert class. In your case we would do something like this:

tempint = Convert.ToInt32(obj);

For more info, check help for the Convert class.

Larsson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top