469,289 Members | 2,330 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,289 developers. It's quick & easy.

How to get the install date of OS?

yxq
Hello,

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

Thank you
Nov 21 '05 #1
6 12147
"yxq" <ga***@163.net> skrev i en meddelelse
news:Of**************@TK2MSFTNGP10.phx.gbl...
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

--
Jens Christian Mikkelsen
http://www.jcmikkelsen.dk
Nov 21 '05 #2
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" <je*********@jcmikkelsenNoSpamPlease.dk> wrote in
message news:%2****************@TK2MSFTNGP10.phx.gbl...
"yxq" <ga***@163.net> skrev i en meddelelse
news:Of**************@TK2MSFTNGP10.phx.gbl...
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

--
Jens Christian Mikkelsen
http://www.jcmikkelsen.dk

Nov 21 '05 #3

"Jens Christian Mikkelsen" <je*********@jcmikkelsenNoSpamPlease.dk> skrev i
en meddelelse news:%2****************@TK2MSFTNGP10.phx.gbl...
"yxq" <ga***@163.net> skrev i en meddelelse
news:Of**************@TK2MSFTNGP10.phx.gbl...
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.


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(oMgmtO bj("InstallDate")))
Next
/Jens

--
Jens Christian Mikkelsen
http://www.jcmikkelsen.dk
Nov 21 '05 #4
yxq
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
"Jens Christian Mikkelsen" <je*********@jcmikkelsenNoSpamPlease.dk> дʼ
news:eY**************@TK2MSFTNGP11.phx.gbl...

"Jens Christian Mikkelsen" <je*********@jcmikkelsenNoSpamPlease.dk> skrev i en meddelelse news:%2****************@TK2MSFTNGP10.phx.gbl...
"yxq" <ga***@163.net> skrev i en meddelelse
news:Of**************@TK2MSFTNGP10.phx.gbl...
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.
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(oMgmtO bj("InstallDate")))
Next
/Jens

--
Jens Christian Mikkelsen
http://www.jcmikkelsen.dk

Nov 21 '05 #5
"yxq" <ga***@163.net> skrev i en meddelelse
news:uG**************@TK2MSFTNGP09.phx.gbl...
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...ime_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
--
Jens Christian Mikkelsen
http://www.jcmikkelsen.dk
Nov 21 '05 #6
yxq
Thank you

"Jens Christian Mikkelsen" <je*********@jcmikkelsenNoSpamPlease.dk> дʼ
news:O0*************@tk2msftngp13.phx.gbl...
"yxq" <ga***@163.net> skrev i en meddelelse
news:uG**************@TK2MSFTNGP09.phx.gbl...
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...ime_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
--
Jens Christian Mikkelsen
http://www.jcmikkelsen.dk

Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Chris Gardner | last post: by
reply views Thread by blupp | last post: by
12 posts views Thread by Etienne | last post: by
3 posts views Thread by Ruslan Shlain | last post: by
7 posts views Thread by p | last post: by
8 posts views Thread by rbt | last post: by
3 posts views Thread by Anthony Smith | last post: by
4 posts views Thread by =?Utf-8?B?S2VuIExlbWlldXg=?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.