Convert 8 bytes binary value to date in registry

Y

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?code/reg/reglastshutdown.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
 
C

Cor Ligthert

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
 

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