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

Convert 8 bytes binary value to date in registry

P: n/a
yxq
There are 8 bytes binary value stored date and time in Registry.
84 8B D7 DF 8B 28 C5 01

I want to convert the binary value to date using VB.NET.

Dim a As FILETIME
a.dwHighDateTime = 29698187 '(01C5288B to decimal)
a.dwLowDateTime = -539522172 '(??????? by 84 8B D7 DF)

MsgBox (GetFileToSystemDate(a, False))
http://vbnet.mvps.org/index.html?cod...stshutdown.htm

*****************************************
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type

Private Function GetFileToSystemDate(ft As FILETIME, _
Optional bIncludeTime As Boolean =
False) As String

Dim buff As String
Dim st As SYSTEMTIME 'system (UNC) time
Dim lt As SYSTEMTIME 'local time
Dim tz As TIME_ZONE_INFORMATION

If FileTimeToSystemTime(ft, st) Then

'retrieve the local time zone info
GetTimeZoneInformation tz

'convert the system time returned above
'to a local time taking the time zone
'info into account
SystemTimeToTzSpecificLocalTime tz, st, lt

'now just write it out
buff = Format$(DateSerial(lt.wYear, lt.wMonth, lt.wDay), "Long Date")

If bIncludeTime Then

buff = buff & " @ " & Format$(TimeSerial(lt.wHour, _
lt.wMinute, _
lt.wSecond), _
"Long Time")
End If

GetFileToSystemDate = buff

Else
GetFileToSystemDate = ""
End If

End Function
************************************************** *******
The vb6 code
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
yxq,

I was curious if I could get this with normal Net instructions. I thought I
succeeded.

Can you try it?

\\\
Dim Reg As Microsoft.Win32.RegistryKey =
Microsoft.Win32.Registry.CurrentUser
Reg =
Microsoft.Win32.Registry.LocalMachine.CreateSubKey ("System\CurrentControlSet\Control\Windows")
Dim LSD As Byte() = DirectCast(Reg.GetValue("ShutdownTime", ""), Byte())
Dim dt As DateTime
dt = dt.AddTicks(BitConverter.ToInt64(LSD, 0))
dt = dt.AddYears(1600)
dt = dt.ToLocalTime
MessageBox.Show(dt.ToString)
///

I hope this helps?

Cor
Nov 21 '05 #2

P: n/a
yxq
Yes, you are right!

Thank you very much
"Cor Ligthert" <no************@planet.nl> 写入消息新闻:%2****************@TK2MSFTNGP10.phx.g bl...
yxq,

I was curious if I could get this with normal Net instructions. I thought
I succeeded.

Can you try it?

\\\
Dim Reg As Microsoft.Win32.RegistryKey =
Microsoft.Win32.Registry.CurrentUser
Reg =
Microsoft.Win32.Registry.LocalMachine.CreateSubKey ("System\CurrentControlSet\Control\Windows")
Dim LSD As Byte() = DirectCast(Reg.GetValue("ShutdownTime", ""), Byte())
Dim dt As DateTime
dt = dt.AddTicks(BitConverter.ToInt64(LSD, 0))
dt = dt.AddYears(1600)
dt = dt.ToLocalTime
MessageBox.Show(dt.ToString)
///

I hope this helps?

Cor

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.