WMI and Win32_NetworkAdapterConfiguration - System.InvalidCastException: Cast from string to Date

M

Mark Hollander

Hi,

I am using the WMI management object to obtain values about the network
cards installed on the system.

The MSDN tells me the following
class Win32_NetworkAdapterConfiguration : CIM_Setting
{
...
datetime DHCPLeaseExpires;
datetime DHCPLeaseObtained;
...
};


When I use the following code

Dim dExpires as DateTime
dExpires = CType(wmi.Item("DHCPLeaseExpires"), DateTime)

I Get the following exception

System.InvalidCastException: Cast from string
"20041109122048.000000+120" to type 'Date' is not valid.
at Microsoft.VisualBasic.CompilerServices.DateType.FromString(String
Value, CultureInfo culture)
at Microsoft.VisualBasic.CompilerServices.DateType.FromString(String
Value)
at Microsoft.VisualBasic.CompilerServices.DateType.FromObject(Object
Value)
at Assimilator.SDK.clsNICProperties.PopulateNetworkAdapterArray() in
V:\VBNET\Assimilator Ver 4.2\Assimilator.SDK\clsNICProperties.vb:line
212


How do I fix ?????

:)

Thank You
Mark Hollander
 
H

Herfried K. Wagner [MVP]

Mark Hollander said:
Dim dExpires as DateTime
dExpires = CType(wmi.Item("DHCPLeaseExpires"), DateTime)

I Get the following exception

System.InvalidCastException: Cast from string

Take a look at the 'System.Management.ManagementDateTimeConverter' class.
 

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