By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,515 Members | 1,178 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,515 IT Pros & Developers. It's quick & easy.

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

P: n/a
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.Fr omString(String
Value, CultureInfo culture)
at Microsoft.VisualBasic.CompilerServices.DateType.Fr omString(String
Value)
at Microsoft.VisualBasic.CompilerServices.DateType.Fr omObject(Object
Value)
at Assimilator.SDK.clsNICProperties.PopulateNetworkAd apterArray() in
V:\VBNET\Assimilator Ver 4.2\Assimilator.SDK\clsNICProperties.vb:line
212
How do I fix ?????

:)

Thank You
Mark Hollander

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"Mark Hollander" <ma**@atcom.co.za> schrieb:
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.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.