WMI and .net

T

tk

I am trying to write a VB.net program that will retrieve info about a
machines hard drive(s). When I try to do a calculation I get and error that
states: Operator is not valid for type 'UInt64' and type 'Integer'. I am
trying to divide the freespace by 1024. I have tried to declare a variable
as type uint64, but that did not work. Is there a way to convert the value
returned by WMI to a type that I can perform math on? Below is the code I am
running:

Dim colDisks As System.Management.ManagementObjectCollection

Dim objDisk As System.Management.ManagementObject

Const HARD_DISK = 3

colDisks = WmiConn.ExecWmiQuery("Select * from Win32_LogicalDisk Where
DriveType = " & HARD_DISK & "")

For Each objDisk In colDisks

F = objDisk.GetPropertyValue("freespace") / 1024

next



Any help would be appreciated.



Thanks.
 
K

Ken Tucker [MVP]

Hi,

Convert it to a long then do math with it.

F = Long.Parse(objDisk.GetPropertyValue("freespace") .ToString) / 1024

Ken
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top