How to get the install date of OS?

  • Thread starter Thread starter yxq
  • Start date Start date
Y

yxq

Hello,

How to get the install date of Operation System(Windows XP) using vb.net?

Thank you
 
yxq said:
How to get the install date of Operation System(Windows XP) using vb.net?

Use WMI to query the Win32_OperatingSystem for the InstallDate attribute.

/Jens
 
HKEY LOCAL MACHINE/SOFTWARE/MICROSOFT/WINDOWS NT/CURRENT VERSION/Install
Date

In the registry

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing
 
Jens Christian Mikkelsen said:
vb.net?

Use WMI to query the Win32_OperatingSystem for the InstallDate attribute.

Here is actual VB.NET code to do what I described above:

Dim dtmInstallDate As DateTime
Dim oSearcher As New ManagementObjectSearcher("SELECT * FROM
Win32_OperatingSystem")
For Each oMgmtObj As ManagementObject In oSearcher.Get
dtmInstallDate =
ManagementDateTimeConverter.ToDateTime(CStr(oMgmtObj("InstallDate")))
Next


/Jens
 
Thank you very much!

But my VB.Net is version 2002, the ManagementDateTimeConverter will be
supported!
How to convert the CStr(oMgmtObj("InstallDate"))? thank you
 
yxq said:
Thank you very much!

But my VB.Net is version 2002, the ManagementDateTimeConverter will be
supported!
How to convert the CStr(oMgmtObj("InstallDate"))? thank you

Oops, I didn't know it wasn't supported in 1.0. The format is WMI specific,
and does not lend itself to direct parsing by .NET. (Which is probably why
MS introduced the converter class.) See the following link for at
description of the format:

http://msdn.microsoft.com/library/en-us/wmisdk/wmi/date_and_time_format.asp

If all you want is the date, you can extract the date part like this:

dtm = DateTime.ParseExact(s.Substring(0, 8), "yyyyMMdd",
Globalization.CultureInfo.InvariantCulture)

(Assuming 's' is a String holding the WMI date from the management object.)
Getting the time of day right requires a bit more arithmetic, as the UTC
offset is specified in minutes.

/Jens
 
Thank you

Jens Christian Mikkelsen said:
Oops, I didn't know it wasn't supported in 1.0. The format is WMI specific,
and does not lend itself to direct parsing by .NET. (Which is probably why
MS introduced the converter class.) See the following link for at
description of the format:

http://msdn.microsoft.com/library/en-us/wmisdk/wmi/date_and_time_format.asp

If all you want is the date, you can extract the date part like this:

dtm = DateTime.ParseExact(s.Substring(0, 8), "yyyyMMdd",
Globalization.CultureInfo.InvariantCulture)

(Assuming 's' is a String holding the WMI date from the management object.)
Getting the time of day right requires a bit more arithmetic, as the UTC
offset is specified in minutes.

/Jens
 

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

Back
Top