PC Review


Reply
Thread Tools Rate Thread

Convert 8 bytes binary value to date in registry

 
 
yxq
Guest
Posts: n/a
 
      14th Mar 2005
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


 
Reply With Quote
 
 
 
 
Cor Ligthert
Guest
Posts: n/a
 
      14th Mar 2005
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


 
Reply With Quote
 
yxq
Guest
Posts: n/a
 
      14th Mar 2005
Yes, you are right!

Thank you very much


"Cor Ligthert" <(E-Mail Removed)> 写入消息新闻:%(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to only read the last 100 bytes from a Binary file? =?Utf-8?B?VGhvbWFzWg==?= Microsoft VB .NET 6 2nd Feb 2007 01:58 PM
dbType.Binary and limit of 0-8000 bytes Chukkalove Microsoft ADO .NET 3 14th Sep 2006 02:31 PM
Convert a string containing a 32-bit binary date to a date data type Remi Caron Microsoft C# .NET 2 22nd Sep 2004 06:23 PM
mscomm32.ocx inserts additional bytes to a binary stream??? arrowlike Microsoft VC .NET 1 13th Sep 2004 11:29 AM
How to replace some bytes of a binary file Mullin Yu Microsoft C# .NET 3 29th Oct 2003 11:17 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:34 AM.